peasant: save almost works

well it does but there's a weird bug when loading it back
This commit is contained in:
Vince Weaver 2021-09-29 00:17:39 -04:00
parent bc788d0d4a
commit 4a32b31c4d
7 changed files with 347 additions and 273 deletions

View File

@ -69,7 +69,8 @@ qload.o: qload.s qboot.inc \
hgr_text_box.s \ hgr_text_box.s \
clear_bottom.s \ clear_bottom.s \
hgr_hgr2.s \ hgr_hgr2.s \
gr_offsets.s gr_offsets.s \
qkumba_popwr.s
ca65 -o qload.o qload.s -l qload.lst ca65 -o qload.o qload.s -l qload.lst
### ###
@ -92,6 +93,8 @@ generate_common.o: generate_common.c
qload.inc: generate_common QLOAD qload.inc: generate_common QLOAD
./generate_common -a 0xb00 -s load_file qload.lst > qload.inc ./generate_common -a 0xb00 -s load_file qload.lst > qload.inc
./generate_common -a 0xb00 -s sector_write qload.lst >> qload.inc
./generate_common -a 0xb00 -s requested_sector qload.lst >> qload.inc
./generate_common -a 0xb00 -s decompress_lzsa2_fast qload.lst >> qload.inc ./generate_common -a 0xb00 -s decompress_lzsa2_fast qload.lst >> qload.inc
./generate_common -a 0xb00 -s getsrc_smc qload.lst >> qload.inc ./generate_common -a 0xb00 -s getsrc_smc qload.lst >> qload.inc
./generate_common -a 0xb00 -s hgr2 qload.lst >> qload.inc ./generate_common -a 0xb00 -s hgr2 qload.lst >> qload.inc
@ -116,6 +119,8 @@ qload.inc: generate_common QLOAD
./generate_common -a 0xb00 -s vgi_simple_rectangle qload.lst >> qload.inc ./generate_common -a 0xb00 -s vgi_simple_rectangle qload.lst >> qload.inc
echo "hposn_high = \$$BA00" >> qload.inc echo "hposn_high = \$$BA00" >> qload.inc
echo "hposn_low = \$$BB00" >> qload.inc echo "hposn_low = \$$BB00" >> qload.inc
echo "driveoff = \$$A22" >> qload.inc
echo "driveon = \$$A9D" >> qload.inc
#### ####

View File

@ -20,7 +20,10 @@ static void find_address(char *symbol_name, int routine_offset) {
while(1) { while(1) {
result=fgets(string,BUFSIZ,fff); result=fgets(string,BUFSIZ,fff);
if (result==NULL) break; if (result==NULL) {
fprintf(stderr,"Error: %s not found!\n",symbol_name);
exit(-1);
}
result=strstr(string,temp_name); result=strstr(string,temp_name);
if (result!=NULL) { if (result!=NULL) {

View File

@ -2,10 +2,33 @@
; o/~ It's the Loading Screen o/~ ; o/~ It's the Loading Screen o/~
; FIXME: we can share some of the code here a bit more
;===================== ;=====================
; load_menu ; load_menu
;===================== ;=====================
load_menu: load_menu:
lda #0
sta loadsave_smc1+1
sta loadsave_smc2+1
jmp common_menu
;=====================
; save_menu
;=====================
save_menu:
lda #1
sta loadsave_smc1+1
sta loadsave_smc2+1
jmp common_menu
;=====================
; common_menu
;=====================
common_menu:
;============================ ;============================
; first read all three saves ; first read all three saves
@ -148,7 +171,7 @@ save_memset:
;==================== ;====================
; draw text box ; draw text box
draw_loadstore_box: draw_loadsave_box:
lda #0 lda #0
sta BOX_X1H sta BOX_X1H
@ -168,13 +191,26 @@ draw_loadstore_box:
;=================== ;===================
; draw main text ; draw main text
draw_loadstore_text: draw_loadsave_text:
; TODO: use SAVE message if we're saving instead loadsave_smc1:
lda #0
bne do_save_message
do_load_message:
; load message
lda #<load_message lda #<load_message
sta OUTL sta OUTL
lda #>load_message lda #>load_message
jmp loadsave_ready
do_save_message:
; save message
lda #<save_message
sta OUTL
lda #>save_message
loadsave_ready:
sta OUTH sta OUTH
jsr disp_put_string jsr disp_put_string
@ -297,8 +333,16 @@ ls_return:
rts rts
do_actual_load: do_actual_load:
loadsave_smc2:
lda #0
bne go_for_save
go_for_load:
jmp load_game jmp load_game
go_for_save:
jmp save_game
ls_done_moving: ls_done_moving:
@ -457,17 +501,22 @@ done_load:
save_game: save_game:
.if 0 ; print are you sure message
; lda #<save_message
; sta OUTL
; lda #>save_message
; sta OUTH
; jsr confirm_action
; bcs done_save jsr confirm_action
pha bcs done_save
; put which save into A
lda INVENTORY_Y
pha ; save slot for later on stack
; clc
; adc #LOAD_SAVE1
; sta WHICH_LOAD ; get proper WHICH_LOAD value
;======================== ;========================
@ -478,22 +527,24 @@ actually_save:
; first load something from ; first load something from
; disk1/track0 to seek the head there ; disk1/track0 to seek the head there
lda WHICH_LOAD lda WHICH_LOAD ; save this value as we
; destroy it for load
pha pha
lda #LOAD_SAVE1 lda #LOAD_SAVE1 ; use SAVE1 as it's on track 0
sta WHICH_LOAD sta WHICH_LOAD
jsr load_file jsr load_file
pla pla
sta WHICH_LOAD sta WHICH_LOAD
; copy save data to $d00 ; copy save data to $BC00
ldx #0 ldx #0
copy_loop: copy_loop:
lda WHICH_LOAD,X lda WHICH_LOAD,X
sta $d00,X sta $BC00,X
inx inx
cpx #(END_OF_SAVE-WHICH_LOAD+1) cpx #(END_OF_SAVE-WHICH_LOAD+1)
bne copy_loop bne copy_loop
@ -512,9 +563,9 @@ copy_loop:
jsr driveoff jsr driveoff
done_save: done_save:
lda #$FF ; reload level as we scrawled on $2000
sta GAME_OVER
jsr change_location ; restore graphics
.endif
rts rts
@ -571,6 +622,9 @@ are_you_sure:
;========================= ;=========================
update_save_info: update_save_info:
lda WHICH_LOAD
pha
ldx #0 ldx #0
update_save_info_loop: update_save_info_loop:
clc clc
@ -595,6 +649,9 @@ update_save_info_loop:
cpx #3 cpx #3
bne update_save_info_loop bne update_save_info_loop
pla
sta WHICH_LOAD
rts rts

View File

@ -62,15 +62,19 @@ parse_show:
cmp #'S' cmp #'S'
bne parse_version bne parse_version
bit LORES ; bit LORES
bit PAGE1 ; bit PAGE1
jsr wait_until_keypress ; jsr wait_until_keypress
bit PAGE2 ; bit PAGE2
bit HIRES ; bit HIRES
jmp done_parse_message ; jmp done_parse_message
jsr save_menu
jmp restore_parse_message
parse_version: parse_version:
cmp #'V' cmp #'V'

View File

@ -1,247 +1,248 @@
; popwr -- code provided by qkumba ; popwr -- code provided by qkumba
frombuff=$d00 ; sector data to write frombuff=$bc00 ; sector data to write
; note these must be contiguous ; note these must be contiguous
encbuf=$e00 ; nibble buffer must be page alined encbuf=$2000 ; nibble buffer must be page alined
bit2tbl=$f00 bit2tbl=$2100
readnib = $1001 readnib = $901
readd5aa: readd5aa:
try_again: try_again:
jsr readnib jsr readnib
try_for_d5: try_for_d5:
cmp #$d5 cmp #$d5
bne try_again bne try_again
jsr readnib jsr readnib
cmp #$aa cmp #$aa
bne try_for_d5 bne try_for_d5
jsr readnib jsr readnib
rts rts
;================================ ;================================
; set up the self-modifying code ; set up the self-modifying code
; to point to the proper slot ; to point to the proper slot
;================================ ;================================
; slot number is in high nibble of A ; slot number is in high nibble of A
popwr_init: popwr_init:
and #$70 ; the slot number is in the top here and #$70 ; the slot number is in the top here
sta slotpatchw1+1 ; self modify the code sta slotpatchw1+1 ; self modify the code
sta slotpatchw2+1 sta slotpatchw2+1
sta slotpatchw3+1 sta slotpatchw3+1
sta slotpatchw4+1 sta slotpatchw4+1
rts rts
;================================ ;================================
; write a sector ; write a sector
;================================ ;================================
sector_write: sector_write:
; convert the input to nibbles ; convert the input to nibbles
ldy #2 ; why start at 2? ldy #2 ; why start at 2?
aa: aa:
ldx #$aa ldx #$aa
b1: b1:
dey dey
frombuff_smc: frombuff_smc:
lda frombuff, y lda frombuff, y
lsr lsr
rol bit2tbl-$aa, x rol bit2tbl-$aa, x
lsr lsr
rol bit2tbl-$aa, x rol bit2tbl-$aa, x
sta encbuf, y sta encbuf, y
lda bit2tbl-$aa, x lda bit2tbl-$aa, x
and #$3f and #$3f
sta bit2tbl-$aa, x sta bit2tbl-$aa, x
inx inx
bne b1 bne b1
tya tya
bne aa bne aa
jmp cmpsecwr jmp cmpsecwr
.align $100 .align $100 ; why do we align? to ensure timing?
; look for the proper sector to write ; look for the proper sector to write
cmpsecwr: cmpsecwr:
b2: b2:
jsr readd5aa ; look for dd55aa marker jsr readd5aa ; look for dd55aa marker
cmp #$96 cmp #$96
bne b2 bne b2
ldy #3 ; try getting the sector number ldy #3 ; try getting the sector number
b3: b3:
jsr readnib jsr readnib
rol rol
sta tmpsec sta tmpsec
jsr readnib jsr readnib
and tmpsec ; and with prev nibble? and tmpsec ; and with prev nibble?
dey dey ; sector value is two bytes
bne b3 bne b3 ; 1 D7 1 D5 1 D3 1 D1
; 1 D6 1 D4 1 D2 1 D0
; so you shift left and AND to get value
requested_sector:
cmp #$d1 requested_sector:
cmp #$d1
bne cmpsecwr ; retry if not what we want?
bne cmpsecwr ; retry if not what we want?
;skip tail #$DE #$AA #$EB some #$FFs ...
;skip tail #$DE #$AA #$EB some #$FFs ...
ldy #$24
b4: ldy #$24
dey b4:
bpl b4 dey
bpl b4
; c0e0 slot 6 ph0 off
; c0e1 slot 6 ph0 on ; c0e0 slot 6 ph0 off
; c0e2 slot 6 ph1 off ; c0e1 slot 6 ph0 on
; c0e3 slot 6 ph1 on ; c0e2 slot 6 ph1 off
; c0e4 slot 6 ph2 off ; c0e3 slot 6 ph1 on
; c0e5 slot 6 ph2 on ; c0e4 slot 6 ph2 off
; c0e6 slot 6 ph3 off ; c0e5 slot 6 ph2 on
; c0e7 slot 6 ph3 on ; c0e6 slot 6 ph3 off
; c0e8 slot 6 motor off ; c0e7 slot 6 ph3 on
; c0e9 slot 6 motor on ; c0e8 slot 6 motor off
; c0ea slot 6 drive 1 ; c0e9 slot 6 motor on
; c0eb slot 6 drive 2 ; c0ea slot 6 drive 1
; c0ec slot 6 q6 off \ Q6 Q7 ; c0eb slot 6 drive 2
; c0ed slot 6 q6 on |-- state machine 0 0 READ ; c0ec slot 6 q6 off \ Q6 Q7
; c0ee slot 6 q7 off | 0 1 WRITE ; c0ed slot 6 q6 on |-- state machine 0 0 READ
; c0ef slot 6 q7 on / 1 0 SENSE WRITE PROTECT ; c0ee slot 6 q7 off | 0 1 WRITE
; 1 1 WRITE LOAD ; c0ef slot 6 q7 on / 1 0 SENSE WRITE PROTECT
; 1 1 WRITE LOAD
; write sector data
; write sector data
slotpatchw1:
ldx #$d1 ; cycle num smc Q6 Q7 slotpatchw1:
lda $c08d, x ; prime drive 1 X ldx #$d1 ; cycle num smc Q6 Q7
lda $c08e, x ; required by Unidisk 1 0 ; senese wp? lda $c08d, x ; prime drive 1 X
tya lda $c08e, x ; required by Unidisk 1 0 ; senese wp?
sta $c08f, x ; 1 1 ; write load tya
ora $c08c, x ; 0 1 ; write sta $c08f, x ; 1 1 ; write load
ora $c08c, x ; 0 1 ; write
; 40 cycles
; 40 cycles
ldy #4 ; 2 cycles
cmp $ea ; nop ; 3 cycles ldy #4 ; 2 cycles
cmp ($ea,x) ; nop ; 6 cycles cmp $ea ; nop ; 3 cycles
b5: cmp ($ea,x) ; nop ; 6 cycles
jsr writenib1 ; (29 cycles) b5:
jsr writenib1 ; (29 cycles)
; +6 cycles
dey ; 2 cycles ; +6 cycles
bne b5 ; 3/2nt dey ; 2 cycles
bne b5 ; 3/2nt
; 36 cycles
; +10 cycles ; 36 cycles
ldy #(prolog_e-prolog) ; +10 cycles
; 2 cycles ldy #(prolog_e-prolog)
cmp $ea ; nop ; 3 cycles ; 2 cycles
b6: cmp $ea ; nop ; 3 cycles
lda prolog-1, y ; 4 cycles b6:
jsr writenib3 ; (17 cycles) lda prolog-1, y ; 4 cycles
jsr writenib3 ; (17 cycles)
; 32 cycles if branch taken
; +6 cycles ; 32 cycles if branch taken
dey ; 2 cycles ; +6 cycles
bne b6 ; 3/2nt dey ; 2 cycles
bne b6 ; 3/2nt
; 36 cycles on first pass
; +10 cycles ; 36 cycles on first pass
tya ; 2 cycles ; +10 cycles
ldy #$56 ; 2 cycles tya ; 2 cycles
b7: ldy #$56 ; 2 cycles
eor bit2tbl-1, y ; 5 cycles b7:
tax ; 2 cycles eor bit2tbl-1, y ; 5 cycles
lda xlattbl, x ; 4 cycles tax ; 2 cycles
slotpatchw2: lda xlattbl, x ; 4 cycles
ldx #$d1 ; slot number smc ; 2 cycles slotpatchw2:
sta $c08d, x ; wp sense ; 5 cycles ldx #$d1 ; slot number smc ; 2 cycles
lda $c08c, x ; read ; 4 cycles sta $c08d, x ; wp sense ; 5 cycles
lda $c08c, x ; read ; 4 cycles
; 32 cycles if branch taken
; 32 cycles if branch taken
lda bit2tbl-1, y ; 5 cycles
dey ; 2 cycles lda bit2tbl-1, y ; 5 cycles
bne b7 ; 3/2nt dey ; 2 cycles
bne b7 ; 3/2nt
; 32 cycles
; +9 cycles ; 32 cycles
clc ; 2 cycles ; +9 cycles
b88: clc ; 2 cycles
eor encbuf, y ; 4 cycles b88:
b8: eor encbuf, y ; 4 cycles
tax ; 2 cycles b8:
lda xlattbl, x ; 4 cycles tax ; 2 cycles
slotpatchw3: lda xlattbl, x ; 4 cycles
ldx #$d1 ; slot number smc ; 2 cycles slotpatchw3:
sta $c08d, x ; wp sense ; 5 cycles ldx #$d1 ; slot number smc ; 2 cycles
lda $c08c, x ; read ; 4 cycles sta $c08d, x ; wp sense ; 5 cycles
bcs f1 ; 3/2nt lda $c08c, x ; read ; 4 cycles
bcs f1 ; 3/2nt
; 32 cycles if branch taken
; 32 cycles if branch taken
lda encbuf, y ; 4 cycles
iny ; 2 cycles lda encbuf, y ; 4 cycles
bne b88 ; 3/2nt iny ; 2 cycles
bne b88 ; 3/2nt
; 32 cycles
; +10 cycles ; 32 cycles
sec ; 2 cycles ; +10 cycles
bcs b8 ; 3 cycles sec ; 2 cycles
bcs b8 ; 3 cycles
; 32 cycles
; +3 cycles ; 32 cycles
f1: ; +3 cycles
ldy #(epilog_e-epilog) f1:
; 2 cycles ldy #(epilog_e-epilog)
cmp ($ea,x) ; nop ; 6 cycles ; 2 cycles
b9: cmp ($ea,x) ; nop ; 6 cycles
lda epilog-1, y ; 4 cycles b9:
jsr writenib3 ; (17 cycles) lda epilog-1, y ; 4 cycles
jsr writenib3 ; (17 cycles)
; 32 cycles if branch taken
; +6 cycles ; 32 cycles if branch taken
dey ; 2 cycles ; +6 cycles
bne b9 ;3/2nt dey ; 2 cycles
bne b9 ;3/2nt
lda $c08e, x ; read/wp
lda $c08c, x ; read lda $c08e, x ; read/wp
lda $c088, x ; motor off lda $c08c, x ; read
rts ; 6 cycles lda $c088, x ; motor off
rts ; 6 cycles
writenib1:
cmp ($ea,x) ; nop ; 6 cycles writenib1:
cmp ($ea,x) ; nop ; 6 cycles cmp ($ea,x) ; nop ; 6 cycles
writenib3: cmp ($ea,x) ; nop ; 6 cycles
slotpatchw4: writenib3:
ldx #$d1 ; slot number ; 2 cycles slotpatchw4:
writenib4: ldx #$d1 ; slot number ; 2 cycles
sta $c08d, x ; wp sense? ; 5 cycles writenib4:
ora $c08c, x ; read ; 4 cycles sta $c08d, x ; wp sense? ; 5 cycles
rts ; 6 cycles ora $c08c, x ; read ; 4 cycles
rts ; 6 cycles
prolog: .byte $ad, $aa, $d5
prolog_e: prolog: .byte $ad, $aa, $d5
epilog: .byte $ff, $eb, $aa, $de prolog_e:
epilog_e: epilog: .byte $ff, $eb, $aa, $de
epilog_e:
xlattbl:
.byte $96,$97,$9A,$9B,$9D,$9E,$9F,$A6 xlattbl:
.byte $A7,$AB,$AC,$AD,$AE,$AF,$B2,$B3 .byte $96,$97,$9A,$9B,$9D,$9E,$9F,$A6
.byte $B4,$B5,$B6,$B7,$B9,$BA,$BB,$BC .byte $A7,$AB,$AC,$AD,$AE,$AF,$B2,$B3
.byte $BD,$BE,$BF,$CB,$CD,$CE,$CF,$D3 .byte $B4,$B5,$B6,$B7,$B9,$BA,$BB,$BC
.byte $D6,$D7,$D9,$DA,$DB,$DC,$DD,$DE .byte $BD,$BE,$BF,$CB,$CD,$CE,$CF,$D3
.byte $DF,$E5,$E6,$E7,$E9,$EA,$EB,$EC .byte $D6,$D7,$D9,$DA,$DB,$DC,$DD,$DE
.byte $ED,$EE,$EF,$F2,$F3,$F4,$F5,$F6 .byte $DF,$E5,$E6,$E7,$E9,$EA,$EB,$EC
.byte $F7,$F9,$FA,$FB,$FC,$FD,$FE,$FF .byte $ED,$EE,$EF,$F2,$F3,$F4,$F5,$F6
.byte $F7,$F9,$FA,$FB,$FC,$FD,$FE,$FF

View File

@ -1,4 +1,6 @@
load_file =$0b20 load_file =$0b20
sector_write =$0c63
requested_sector =$0d17
decompress_lzsa2_fast =$0de6 decompress_lzsa2_fast =$0de6
getsrc_smc =$0edc getsrc_smc =$0edc
hgr2 =$16e3 hgr2 =$16e3
@ -23,3 +25,5 @@ hgr_put_char_cursor =$0f15
vgi_simple_rectangle =$12ef vgi_simple_rectangle =$12ef
hposn_high = $BA00 hposn_high = $BA00
hposn_low = $BB00 hposn_low = $BB00
driveoff = $A22
driveon = $A9D

View File

@ -20,7 +20,7 @@
.byte $00 ; KERREK_STATE = $9C .byte $00 ; KERREK_STATE = $9C
.byte $00 ; ARROW_SCORE = $9D .byte $00 ; ARROW_SCORE = $9D
.byte $01 ; SCORE_HUNDREDS= $9E .byte $01 ; SCORE_HUNDREDS= $9E
.byte $09 ; SCORE_TENSONES= $9F .byte $39 ; SCORE_TENSONES= $9F
.byte $FF ; INVENTORY_1 = $A0 .byte $FF ; INVENTORY_1 = $A0
.byte $FF ; INVENTORY_2 = $A1 .byte $FF ; INVENTORY_2 = $A1
.byte $FF ; INVENTORY_3 = $A2 .byte $FF ; INVENTORY_3 = $A2