some comments

This commit is contained in:
4am 2020-09-23 18:52:15 -04:00
parent c55e7b982d
commit 7a796c3928
9 changed files with 208 additions and 63 deletions

Binary file not shown.

View File

@ -129,8 +129,18 @@
;$09BF> EA: NOP ; 2
;$09C0> 50 A3: BVC $0965 ; 4 *!*
;
!zone {
!align $FF,0,0 ; align to page
;------------------------------------------------------------------------------
; ElectricDuet
; play 2-voice music in Electric Duet format
;
; in: $1E/$1F points to music data
; out: all flags and registers clobbered
; will exit when it finishes playing (music data is 0-0-0 terminated)
; will also exit on keypress, but you must check $C000 yourself to see
; if that happened
;------------------------------------------------------------------------------
!align $FF,0,0 ; align to page (essential)
ElectricDuet
ED0900 LDA #$01 ; 2 *!*
ED0902 STA $09 ; 3
@ -239,4 +249,3 @@ ED09BB EOR #$80 ; 2 *!*
ED09BD BVS ED0962 ; 4 *!*
ED09BF NOP ; 2
ED09C0 BVC ED0965 ; 4 *!*
}

View File

@ -45,8 +45,10 @@ CMD_SETEOF = $02D0 ; set file size
; +3 [word] address of data buffer (to receive file contents)
; +5 [word] maximum length of data to read
; +7 [word] address of ProDOS file buffer
; out: if C set, load failed and A contains error code from open or read
; out: if C set, load failed and A = error code from open or read
; if C clear, load succeeded
; Y clobbered
; X preserved
; all other flags & registers clobbered
;------------------------------------------------------------------------------
LoadFile1Shot
@ -89,10 +91,12 @@ LoadFile1Shot
; +6 [word] address of data buffer
; +8 [word] length of data buffer
; +A [word] address of ProDOS file buffer
; out: if C set, save failed and A contains error code
; out: if C set, save failed and A = error code
; from open or write
; if C clear, save succeeded
; all other flags & registers clobbered
; Y clobbered
; X preserved
; other flags clobbered
;------------------------------------------------------------------------------
SaveFile1Shot
+PARAMS_ON_STACK 11
@ -149,8 +153,11 @@ SaveFile1Shot
; +1 address of pathname
; +3 [byte] file type
; +4 [word] aux file type
; out: if error, C set and A contains error code
; out: if error, C set and A = error code
; if success, C clear
; Y clobbered
; X preserved
; other flags clobbered
;------------------------------------------------------------------------------
CreateFile
+PARAMS_ON_STACK 5
@ -173,11 +180,14 @@ CreateFile
; OpenFile
; open file via ProDOS MLI
;
; in: stack contains 4 bytes of parameters:
; +1 [word] address of filename
; +3 [word] ProDOS file buffer
; out: if C set, open failed and A contains error code
; if C clear, open succeeded and A contains file reference number
; in: stack contains 4 bytes of parameters:
; +1 [word] address of filename
; +3 [word] ProDOS file buffer
; out: if C set, open failed and A = error code
; if C clear, open succeeded and A = file reference number
; Y clobbered
; X preserved
; other flags clobbered
;------------------------------------------------------------------------------
OpenFile
+PARAMS_ON_STACK 4
@ -195,14 +205,17 @@ OpenFile
; ReadFile
; read an open file via ProDOS MLI
;
; in: stack contains 5 bytes of parameters:
; +1 [byte] ProDOS file reference number
; +2 [word] address of data buffer (to receive file contents)
; +4 [word] maximum length of data to read
; out: if C set, read failed and A contains error code
; if C clear, read succeeded and A contains the same
; file reference number that was passed in
; stack set to next instruction after parameters
; in: stack contains 5 bytes of parameters:
; +1 [byte] ProDOS file reference number
; +2 [word] address of data buffer (to receive file contents)
; +4 [word] maximum length of data to read
; out: if C set, read failed and A = error code
; if C clear, read succeeded and A = the same
; file reference number that was passed in
; Y clobbered
; X preserved
; other flags clobbered
; stack set to next instruction after parameters
;------------------------------------------------------------------------------
ReadFile
+PARAMS_ON_STACK 5
@ -223,9 +236,12 @@ ReadFile
; stack contains 4 bytes of parameters:
; +1 [word] address of data buffer
; +3 [word] length of data buffer
; out: if C set, save failed and A contains error code
; if C clear, write succeeded and A contains the same file reference
; out: if C set, save failed and A = error code
; if C clear, write succeeded and A = the same file reference
; number that was passed in
; Y clobbered
; X preserved
; other flags clobbered
;------------------------------------------------------------------------------
WriteFile
sta mliparam+1 ; file reference number
@ -234,7 +250,7 @@ WriteFile
+LDPARAM16 3, mliparam+4 ; data buffer length
+LDADDR CMD_WRITE
jsr mli
bcs + ; error, A contains MLI error code
bcs + ; error, A = MLI error code
lda mliparam+1 ; no error, return file reference number
+ rts
@ -243,9 +259,12 @@ WriteFile
; set file position within an open file to the beginning of the file
;
; in: A = file reference number
; out: if C set, save failed and A contains error code
; if C clear, write succeeded and A contains the same file reference
; out: if C set, save failed and A = error code
; if C clear, write succeeded and A = the same file reference
; number that was passed in
; Y clobbered
; X preserved
; other flags clobbered
;------------------------------------------------------------------------------
SetMarkTo0
sta mliparam+1 ; file reference number
@ -261,8 +280,11 @@ SetMarkTo0
; flush an open file (actually writes it to disk, but without closing it)
;
; in: A = file reference number
; out: if error, C set and A contains error code
; out: if error, C set and A = error code
; if success, C clear
; Y clobbered
; X preserved
; other flags clobbered
;------------------------------------------------------------------------------
FlushFile
sta mliparam+1 ; file reference number
@ -273,9 +295,12 @@ FlushFile
; CloseFile
; close an open file
;
; in: A = file reference number
; out: if error, C set and A contains error code
; if success, C clear
; in: A = file reference number
; out: if error, C set and A = error code
; if success, C clear
; Y clobbered
; X preserved
; other flags clobbered
;------------------------------------------------------------------------------
CloseFile
sta mliparam+1 ; file reference number
@ -285,8 +310,8 @@ CloseFile
;------------------------------------------------------------------------------
; Quit
; quit to ProDOS
; in: none
; out: does not return
; in: none
; out: does not return
;------------------------------------------------------------------------------
Quit
lda #0
@ -297,11 +322,11 @@ Quit
; mli
; low-level MLI wrapper
;
; in: A = MLI command code
; Y = number of MLI parameters
; caller has filled mliparam with all relevant parameters
; out: returns immediately after calling MLI, so whatever state
; the MLI routine sets, the caller will see it verbatim
; in: A = MLI command code
; Y = number of MLI parameters
; caller has filled mliparam with all relevant parameters
; out: returns immediately after calling MLI, so whatever state
; the MLI routine sets, the caller will see it verbatim
;------------------------------------------------------------------------------
mli sta mlicmd ; store command code
sty mliparam ; number of parameters

View File

@ -7,15 +7,21 @@
; - LoopSound
; - PlaySound
; - PlaySoundToCompletion
; - InitPuzzleSound
; - PlayNextChord
; - PlayFinalChord
; - ErrorSound
;
gMockingboardSlot
!byte 0
; Public variables:
; - gSoundPref
;
gSoundPref
!byte 1 ; 0 = no sound, 1 = sound
mockingboardSlot ; [byte][private]
!byte 0 ; 0 = no Mockingboard, 0xC1..0xC7 = slot number
progressionIndex ; [byte][private]
!byte 0
@ -52,10 +58,26 @@ kFinalChord
kErrorSound
!word M_ERROR
;------------------------------------------------------------------------------
; ReinitSoundAfterPrefChange
; reinitialize self-modified code that relies on preference values
;
; in: none
; out: all flags & registers clobbered
;------------------------------------------------------------------------------
ReinitSoundAfterPrefChange
ldx gMockingboardSlot
ldx mockingboardSlot
; /!\ execution falls through to InitSound
;------------------------------------------------------------------------------
; InitSound
; initialize self-modified code for playing music and sound
;
; in: X = Mockingboard slot, or 0 if no Mockingboard present
; out: all flags & registers clobbered
;------------------------------------------------------------------------------
InitSound
stx gMockingboardSlot
stx mockingboardSlot
lda gSoundPref
beq @theSoundOfSilence
cpx #0
@ -73,9 +95,30 @@ InitSound
-
+LD16 $FE
; /!\ execution falls through to LoopSound
;------------------------------------------------------------------------------
; LoopSound
; play sound data repeatedly until keypress
;
; in: A/Y points to buffer containing sound data in Electric Duet format
; out: A = key pressed
; all other flags & registers clobbered
;------------------------------------------------------------------------------
LoopSound
sec
+HIDE_NEXT_BYTE
; /!\ execution falls through to PlaySound
;------------------------------------------------------------------------------
; PlaySound
; play sound data once, or until keypress, whichever comes first
;
; in: A/Y points to buffer containing sound data in Electric Duet format
; out: N = 1 if exited because key was pressed, and A = key pressed
; N = 0 if exited because all sound data was played
; all other flags & registers clobbered
;------------------------------------------------------------------------------
PlaySound
clc
php
@ -90,36 +133,57 @@ SoundLibraryDispatch=*+1
+ lda KBD
Silence rts
;------------------------------------------------------------------------------
; PlaySoundToCompletion
; play sound data once, ignoring keypresses
;
; in: A/Y points to buffer containing sound data in Electric Duet format
; out: all flags & registers clobbered
;------------------------------------------------------------------------------
PlaySoundToCompletion
pha
lda ED0974+1
sta @restoreED
lda MBKEYBRANCH+1
sta @restoreMB
lda #0
sta ED0974+1
sta MBKEYBRANCH+1
lda #0 ; just self-modify sound routines to branch
sta ED0974+1 ; to next instruction on keypress, because
sta MBKEYBRANCH+1 ; cycle counts are critical
pla
jsr PlaySound
php
pha
@restoreED=*+1
lda #$FD ; SMC
sta ED0974+1
sta ED0974+1 ; restore sound routines
@restoreMB=*+1
lda #$FD ; SMC
sta MBKEYBRANCH+1
pla
plp
rts
;------------------------------------------------------------------------------
; InitPuzzleSound
; initialize chord progression at the start of a new puzzle
;
; in: none
; out: A clobbered
; N = 1
; Z = 0
; all other flags & registers preserved
;------------------------------------------------------------------------------
InitPuzzleSound
lda #$FF
sta progressionIndex
rts
;------------------------------------------------------------------------------
; PlayNextChord
; play next chord progression during a puzzle
;
; in: none
; out: A, Y clobbered
; X preserved
; flags clobbered
;------------------------------------------------------------------------------
PlayNextChord
; out: preserves X
txa
pha
lda gWorldID
@ -151,8 +215,16 @@ PlayNextChord
tax
rts
;------------------------------------------------------------------------------
; PlayFinalChord
; play final chord progression when completing a puzzle
;
; in: none
; out: A, Y clobbered
; X preserved
; flags clobbered
;------------------------------------------------------------------------------
PlayFinalChord
; out: preserves X
txa
pha
+LD16 kFinalChord
@ -161,6 +233,15 @@ PlayFinalChord
tax
rts
ErrorSound
;------------------------------------------------------------------------------
; PlayErrorChord
; play error sound when attempting an illegal move
;
; in: none
; out: A, Y clobbered
; X preserved
; flags clobbered
;------------------------------------------------------------------------------
PlayErrorSound
+LD16 kErrorSound
jmp PlaySound
jmp PlaySoundToCompletion

View File

@ -8,6 +8,8 @@
; based on routine by John Brooks
; posted on comp.sys.apple2 on 2018-07-11
; https://groups.google.com/d/msg/comp.sys.apple2/v2HOfHOmeNQ/zD76fJg_BAAJ
; clobbers A,X
; preserves Y
!macro BUILD_HGR_LOOKUP_TABLES .hgrlo, .hgr1hi {
ldx #0
- txa
@ -19,14 +21,14 @@
ora #5
+ asl
asl
sta .hgrlo,x
sta .hgrlo, x
txa
and #7
rol
asl .hgrlo,x
asl .hgrlo, x
rol
ora #$20
sta .hgr1hi,x
sta .hgr1hi, x
inx
cpx #$C0
bne -
@ -35,7 +37,8 @@
; for functions that take parameters on the stack
; set (PARAM) to point to the parameters and
; move the stack pointer to the first byte after the parameters
; clobbers A,X,Y
; clobbers A,Y
; preserves X
!macro PARAMS_ON_STACK .bytes {
pla
sta PARAM
@ -54,6 +57,8 @@
; load a 16-bit value from the parameters on the stack
; then store it as new source
; (assumes PARAMS_ON_STACK was used first)
; clobbers A,Y
; preserves X
!macro LDPARAM16 .offset,.dest {
ldy #.offset
lda (PARAM),y
@ -67,6 +72,8 @@
; load an 8-bit value from the parameters on the stack
; then store it as new source
; (assumes PARAMS_ON_STACK was used first)
; clobbers A,Y
; preserves X
!macro LDPARAM8 .offset,.dest {
ldy #.offset
lda (PARAM),y
@ -74,24 +81,28 @@
}
; load the address of .ptr into A (low) and Y (high)
; preserves X
!macro LDADDR .ptr {
lda #<.ptr
ldy #>.ptr
}
; load a 16-bit value into A (low) and Y (high)
; preserves X
!macro LD16 .ptr {
lda .ptr
ldy .ptr+1
}
; store a 16-bit value from A (low) and Y (high)
; preserves X
!macro ST16 .ptr {
sta .ptr
sty .ptr+1
}
; decrement a 16-bit value in A (low) and Y (high)
; preserves X
!macro DEC16 {
sec
sbc #1
@ -101,6 +112,7 @@
}
; increment a 16-bit value in A (low) and Y (high)
; preserves X
!macro INC16 {
clc
adc #1
@ -110,6 +122,7 @@
}
; increment a 16-bit value stored at an address
; preserves A,X,Y
!macro INCADDR .addr {
inc .addr
bne +
@ -118,6 +131,7 @@
}
; compare a 16-bit value in A (low) and Y (high) to an absolute address
; preserves A,X,Y
!macro CMP16ADDR .addr {
cmp .addr
bne +
@ -126,6 +140,7 @@
}
; compare a 16-bit value in A (low) and Y (high) to an immediate value
; preserves A,X,Y
!macro CMP16 .val {
cmp #<.val
bne +
@ -133,38 +148,48 @@
+
}
; long-BPL
; preserves A,X,Y
!macro LBPL .target {
bmi +
jmp .target
+
}
; long-BNE
; preserves A,X,Y
!macro LBNE .target {
beq +
jmp .target
+
}
; long-BCS
; preserves A,X,Y
!macro LBCS .target {
bcc +
jmp .target
+
}
; preserves A,X,Y
!macro READ_ROM_NO_WRITE {
bit $C082
}
; use BIT to swallow the following 1-byte opcode
; preserves A,X,Y
!macro HIDE_NEXT_BYTE {
!byte $24
}
; use BIT to swallow the following 2-byte opcode
; preserves A,X,Y
!macro HIDE_NEXT_2_BYTES {
!byte $2C
}
; preserves A,X,Y
!macro RTS_IF_KEY {
bit $c000
bpl +
@ -172,6 +197,7 @@
+
}
; clobbers all registers & flags
!macro PRINT_AT .str, .vtab, .htab {
lda #.vtab
sta VTAB
@ -181,7 +207,8 @@
jsr DrawHeavySilkString
}
; debugging
; wait for keypress (for debugging)
; preserves A,X,Y
!macro DEBUGWAIT {
bit $c010
- bit $c000

View File

@ -17,8 +17,8 @@
FirstMover
!pseudopc $4000 {
Start
jsr LoadPrefs
Start ; X = Mockingboard slot (from init)
jsr LoadPrefs ; preserves X
jsr InitSound
jsr LoadProgressFromDisk
jsr TitlePage

View File

@ -24,6 +24,9 @@ DEFAULTCHEAT = $30 ; ASCII '0'
;------------------------------------------------------------------------------
; LoadPrefs
; load settings from disk
;
; in: none
; out: X preserved
;------------------------------------------------------------------------------
LoadPrefs
jsr LoadFile1Shot

View File

@ -21,7 +21,7 @@ DrawHeavySilkString
inc $FF
+
+LD16 $FE
; /!\ execution falls through here to DrawHeavySilk
; /!\ execution falls through here to DrawHeavySilkBuffer
DrawHeavySilkBuffer
; A/Y contains address of character buffer (characters 0x20..0x5A only)

View File

@ -145,7 +145,7 @@ PlayEventDownArrow
jsr ScrollPuzzleDown
bcc +
CantMove
jsr ErrorSound
jsr PlayErrorSound
KeepPlaying
ldx #kKeepPlaying
rts
@ -198,7 +198,7 @@ PlayEventLetter
ldy gSelectedLogicalColumn
jsr FindLetterInColumn
bcc +
jsr ErrorSound ; didn't find letter, we're done
jsr PlayErrorSound ; didn't find letter, we're done
ldx #kKeepPlaying
rts
+ beq PlayEventRightArrow ; found letter but it's already on center row, we're done, exit through right arrow handler