Skip to content

Commit

Permalink
animated loading bar -b option
Browse files Browse the repository at this point in the history
  • Loading branch information
datajerk committed Apr 23, 2017
1 parent 5e83553 commit 695afe6
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 17 deletions.
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ windows: bin/c2d.exe bin/text2page.exe bin/page2text.exe

dist: all windows

c2d.h: c2d.h.0 asm/loader.s makeheader
c2d.h: c2d.h.0 asm/loader.s asm/bar.s makeheader
./makeheader

bin/c2d: c2d.c c2d.h holes.h
Expand Down Expand Up @@ -42,6 +42,28 @@ gameserverclient.text: Makefile
text="CASSETTE PORT FTW! ---- ASCIIEXPRESS.NET"; printf "%*s\n" $$((($${#text}+40)/2)) "$$text"; \
) | tail -24 >$@

barloader.text: Makefile
( \
echo; \
figlet -c -w 40 -f poison "c2d"; \
echo; \
text="C2D (CODE TO DISK) BUILT-IN LOADER"; printf "%*s\n" $$((($${#text}+40)/2)) "$$text"; \
echo; \
text="LOADING GAME SERVER CLIENT ..."; printf "%*s\n" $$((($${#text}+40)/2)) "$$text"; \
echo; \
text="________________________________________"; printf "%*s\n" $$((($${#text}+40)/2)) "$$text"; \
text="________________________________________"; printf "%*s\n" $$((($${#text}+40)/2)) "$$text"; \
echo; \
echo; \
text="HTTPS://GITHUB.COM/DATAJERK/C2D/"; printf "%*s\n" $$((($${#text}+40)/2)) "$$text"; \
) | tail -24 >$@

barloader.textpage: barloader.text bin/text2page
bin/text2page <$< >$@

gameserverclientbar.dsk: barloader.textpage gameserverclient bin/c2d
bin/c2d -b -t $< gameserverclient,800 $@

fulltest: gameserverclient gameserverclient.mon gameserverclient.text dist
EMU=1 WIN=1 ./test.sh

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ Windows/MinGW:

```
usage: c2d [-vh?]
c2d [-mu] [-t filename] [-s start address override] input[.mon],[load_address] output.dsk
c2d [-bum] [-t filename] [-s start address override] input[.mon],[load_address] output.dsk
-h|? this help
-m jump to monitor after booting
-s XXXX jump to XXXX after booting
-t filename, where filename is a 1K $400-$7FF text page splash screen
The splash screen will display while the binary is loading
-u do not patch screen holes
-b animated loading bar (experimental)
-v print version number and exit
Input without a .mon extension is assumed to be a binary with a 4 byte header.
Expand Down Expand Up @@ -104,7 +105,7 @@ Yes. No input checking. Big Endian untested.

### The Ugly Stuff

c2d, Code to Disk, Version 0.53
c2d, Code to Disk, Version 0.54

(c) 2012,2017 All Rights Reserved, Egan Ford ([email protected])

Expand Down
167 changes: 167 additions & 0 deletions asm/bar.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
;bar.s
;
; moves itself to another page memory,
; then reads binary from disk using params at end,
; then jumps to binary
;

; apple params/vectors

warm = $FF69 ; back to monitor
bell = $FBDD ; ding
preg = $48 ; mon p reg
ch = $24 ; cursor horizontal
movecur = $FB5B ; move cursor to ch,a
cout = $FDED ; character out sub

; dos params/vectors

rwtsprm = $B7E8 ; looked at dos 3.3 disk, not using $3E3 to find
rwts = $B7B5 ; rwts jsr

; vars

stage1 = $800
stage2 = $300 ; $300 looks open
invsp = $20 ; inverse space for draw
;;;run time
trkcnt = $00 ; track counter
segcnt = $01 ; loop var
buffer = $02 ; MSB of RWTS buffer
secnum = $03 ; loop var
trknum = $04 ; loop var
barcnt = $05 ; bar counter
barptr = $06 ; bar pointer


.org stage1
init:
lda #0 ; reset pointer and counter
sta barcnt
sta barptr

lda #1 ; read(1)/write(2) command
ldy #$0C ; offset in RWTS
sta rwtsprm,y ; write it to RWTS

lda #0 ; buffer LSB
ldy #8 ; offset in RWTS
sta rwtsprm,y ; write it to RWTS

lda #2
sta trknum ; start with track 2

start:
ldx #0 ; move code to stage2
move:
lda moved,x
sta loader,x
inx
cpx #$D0
bne move ; move 208 bytes
jmp loader

moved:
.org stage2

loader:
lda loadpage ; where to dump the tracks
sta buffer

ldx lasttrack
dex ; because data starts at track 2
dex
stx trkcnt ; number of complete and partial tracks

;;;begin track loop
trkloop:
lda trknum ; track number
ldy #4 ; offset in RWTS
sta rwtsprm,y ; write it to RWTS

;;;begin sector loop (16), backwards is faster, much faster
lda trkcnt ; check if last track
bne fulltrack ; if not then full track
lda lastsector ; if so, get last sector number
bpl subtrack
fulltrack:
lda #$F
subtrack:
sta secnum
secloop:
lda secnum ; sector number
ldy #5 ; offset in RWTS
sta rwtsprm,y ; write it to RWTS

lda buffer ; buffer MSB
clc
adc secnum ; compute page load address
ldy #9 ; offset in RWTS
sta rwtsprm,y ; write it to RWTS

ldy #<rwtsprm ; load rwts paramlist B7E8
lda #>rwtsprm
jsr rwts ; do it!
bcs diskerror
lda #0
sta preg ; fix p reg so mon is happy

;;;draw code
inc barcnt ; sectors read
ldx barptr ; get current pointer value
lda bar,x
cmp barcnt ; is bar,x = barcnt?
bne nodraw ; if bar,x = barcnt draw bar
lda barptr ; get position
;clc
;adc #5 ; intend
sta ch
lda #19 ; row 19
jsr movecur
lda #invsp
jsr cout
inc barptr ; move pointer to next bar position
nodraw:
;;;end draw code

dec secnum
bpl secloop
;;;end sector loop

lda buffer ; buffer += $10
clc
adc #$10
sta buffer

inc trknum ; next track
dec trkcnt ;
bpl trkloop ; 0, all done with tracks
;;;end track loop

done:
jmp (nextjump) ; down with load, run it

diskerror:
jmp warm

lasttrack:
.org *+1
lastsector:
.org *+1
loadpage:
.org *+1
nextjump:
.org *+2
bar:
.org *+40
;;; used for debug
;trkcnt:
; .org *+1
;segcnt:
; .org *+1
;buffer:
; .org *+1
;secnum:
; .org *+1
;trknum:
; .org *+1
Binary file modified bin/c2d
Binary file not shown.
Binary file modified bin/c2d.exe
Binary file not shown.
Binary file modified bin/page2text.exe
Binary file not shown.
Binary file modified bin/text2page.exe
Binary file not shown.
49 changes: 37 additions & 12 deletions c2d.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
c2d, Code to Disk, Version 0.53
c2d, Code to Disk, Version 0.54
(c) 2012,2017 All Rights Reserved, Egan Ford ([email protected])
Expand Down Expand Up @@ -43,7 +43,7 @@ Based on work by:
#include "c2d.h"
#include "holes.h"

#define VERSION "Version 0.53"
#define VERSION "Version 0.54"
#define INFILE argv[argc-2]
#define OUTFILE argv[argc-1]
#define BINARY 0
Expand All @@ -57,13 +57,13 @@ int main(int argc, char **argv)
{
FILE *ifp, *ofp;
int c, i, j, k, start = 0, loadaddress, inputtype, warm = 0, filesize = 0, unpatch = 0;
int loaderstart, loader = 0, loadersize = 0, textpagesize = 0;
int loaderstart, loader = 0, loadersize = 0, loaderbasesize = 0, textpagesize = 0, bar = 0;
struct stat st;
char *filetypes[] = { "BINARY", "MONITOR" };
char *ext, filename[256], load_address[10], *textpage = NULL;

opterr = 1;
while ((c = getopt(argc, argv, "t:vmh?s:u")) != -1)
while ((c = getopt(argc, argv, "t:vmh?s:ub")) != -1)
switch (c) {
case 't': // load a splash page while loading binary
loader = 1;
Expand All @@ -83,6 +83,9 @@ int main(int argc, char **argv)
case 'u':
unpatch = 1;
break;
case 'b':
bar = 1;
break;
case 'h': // help
case '?':
usage();
Expand Down Expand Up @@ -218,8 +221,7 @@ int main(int argc, char **argv)
fclose(ifp);

// patch holes
if(!unpatch)
{
if(!unpatch) {
uint64_t *p = (uint64_t *)&blank.track[1].sector[0].byte[0]; // set to start of splash page
uint64_t *h = (uint64_t *)&holes; // holes are 64-bits
int i;
Expand All @@ -232,13 +234,26 @@ int main(int argc, char **argv)
}
}

if ((loadersize = sizeof(loadercode)) > 256) {
fprintf(stderr, "Loader code size %d > 256\n\n", loadersize);
return 1;
if(!bar) {
loaderbasesize = sizeof(loadercode);
if ((loadersize = sizeof(loadercode)) > 256) {
fprintf(stderr, "Loader code size %d > 256\n\n", loadersize);
return 1;
}

for (i = 0; i < loadersize; i++)
blank.track[1].sector[4].byte[i] = loadercode[i];
}
else {
loaderbasesize = sizeof(barcode);
if ((loadersize = sizeof(barcode)) > 256) {
fprintf(stderr, "Loader code size %d > 256\n\n", loadersize);
return 1;
}

for (i = 0; i < loadersize; i++)
blank.track[1].sector[4].byte[i] = loadercode[i];
for (i = 0; i < loadersize; i++)
blank.track[1].sector[4].byte[i] = barcode[i];
}

// loader args
// lasttrack
Expand All @@ -252,6 +267,16 @@ int main(int argc, char **argv)
// program start MSB
blank.track[1].sector[4].byte[loadersize + 4] = start >> 8;

//bar code, pre compute status bar table
if(bar) {
int num_sectors = (int) ceil((filesize + (loadaddress & 0xFF)) / 256.0);
int bar_length = 40;
int i;

for(i = 1; i <= bar_length; i++)
blank.track[1].sector[4].byte[loadersize + 4 + i] = i * num_sectors / bar_length;
}

loaderstart = 0x400;

// temp hack to effect the sound of the drive, i.e. to make consistent
Expand All @@ -278,7 +303,7 @@ int main(int argc, char **argv)

fprintf(stderr, "After boot, jump to: $%04X\n", loaderstart);
fprintf(stderr, "\n");
fprintf(stderr, "Writing %s to T:02/S:00 - T:%02d/S:%02d on %s\n\n", filename, blank.track[1].sector[4].byte[sizeof(loadercode)], blank.track[1].sector[4].byte[sizeof(loadercode) + 1], OUTFILE);
fprintf(stderr, "Writing %s to T:02/S:00 - T:%02d/S:%02d on %s\n\n", filename, blank.track[1].sector[4].byte[sizeof(loadercode)], blank.track[1].sector[4].byte[loaderbasesize + 1], OUTFILE);
}

if ((ofp = fopen(OUTFILE, "wb")) == NULL) {
Expand Down
Loading

0 comments on commit 695afe6

Please sign in to comment.