~rabbits/donsol

cf31ab32760f7e5b573a933e83f8f8541c501f4f — Devine Lu Linvega 1 year, 2 months ago 013f0d6
Added sound toggle dialogs
14 files changed, 239 insertions(+), 80 deletions(-)

M build.sh
M push.sh
M src/deck.asm
M src/game.asm
M src/head.asm
M src/init.asm
M src/main.asm
M src/player.asm
M src/room.asm
M src/sound.asm
M src/splash.asm
M src/tables.asm
R tools/{debug-zeropage.lua => zeropage.lua}
A zeropage.lua
M build.sh => build.sh +2 -1
@@ 33,4 33,5 @@ echo "Assembling new cart."
tools/asm6 src/cart.asm cart.nes

# Run
fceux cart.nes --loadlua debug.lua
# fceux cart.nes --loadlua zeropage.lua
fceux cart.nes 

M push.sh => push.sh +4 -8
@@ 1,14 1,10 @@
#!/bin/bash

# Build
rm cart.nes
./tools/asm6 src/cart.asm cart.nes

# Push
rm -r release
mkdir release
cp cart.nes release/cart.nes
cp README.txt release/README.txt
~/Applications/butler push ~/Repositories/Hundredrabbits/Donsol/release hundredrabbits/donsol:nes
~/Applications/butler status hundredrabbits/donsol
rm -r release
\ No newline at end of file
cp README release/README
~/butler push release hundredrabbits/donsol:nes
~/butler status hundredrabbits/donsol
rm -r release

M src/deck.asm => src/deck.asm +9 -0
@@ 100,6 100,7 @@ pickPotion@deck:               ;
	; when sick
	LDA #$01                     ; dialog:sickness
	JSR show@dialog
	JSR PotionError@sound
	RTS 
@tryWaste:                     ;
	LDA hp@player


@@ 108,6 109,7 @@ pickPotion@deck:               ;
	; when already full health
	LDA #$07                     ; dialog:potion
	JSR show@dialog
	JSR PotionError@sound
	RTS 
@heal:                         ;
	LDA hp@player


@@ 118,6 120,7 @@ pickPotion@deck:               ;
	JSR clampHealth@player
	LDA #$06                     ; dialog:potion
	JSR show@dialog
	JSR Potion@sound
	RTS 

;; turn(shield)


@@ 129,6 132,7 @@ pickShield@deck:               ;
	STA dp@player
	LDA #$05                     ; dialog: shield
	JSR show@dialog
	JSR Shield@sound
	RTS 

;; turn(attack)


@@ 144,6 148,7 @@ pickEnemy@deck:                ;
	LDA card_last_value
	STA damages@player
	JSR runDamages
	JSR EnemyBad@sound
	RTS 
@blocking:                     ;
	; check if shield breaking


@@ 160,6 165,7 @@ pickEnemy@deck:                ;
	LDA card_last_value
	STA damages@player
	JSR runDamages
	JSR ShieldError@sound
	RTS 
@shielded:                     ;
	; check for overflow


@@ 177,6 183,7 @@ pickEnemy@deck:                ;
	; damage shield
	LDA card_last_value
	STA dp@player
	JSR EnemyMedium@sound
	RTS 
@blocked:                      ;
	; damage shield


@@ 184,6 191,7 @@ pickEnemy@deck:                ;
	STA dp@player
	LDA #$0A                     ; dialog:blocked
	JSR show@dialog
	JSR EnemyGood@sound
	RTS 

;; damages


@@ 198,6 206,7 @@ runDamages:                    ;
	STA sp@player
	LDA #$03                     ; dialog:death
	JSR show@dialog
	JSR Death@sound
	RTS                          ; stop attack phase
@survive:                      ;
	LDA hp@player

M src/game.asm => src/game.asm +0 -1
@@ 7,7 7,6 @@ show@game:                     ;
	STA reqdraw_cursor
	STA view@game                ; set view
	JSR restart@game             ; restart
	JSR Enter@sound
	RTS 

restart@game:                  ;

M src/head.asm => src/head.asm +12 -1
@@ 25,6 25,14 @@ APUCH2VOL           .equ $4004
APUCH2SWP           .equ $4005 
APUCH2FRQ           .equ $4006 
APUCH2LEN           .equ $4007 
APUCH3CNT           .equ $4008 
APUCH3SWP           .equ $4009 
APUCH3FRQ           .equ $400a 
APUCH3LEN           .equ $400b 
APUCH4VOL           .equ $400c 
APUCH4SWP           .equ $400d 
APUCH4FRQ           .equ $400e 
APUCH4LEN           .equ $400f 
SPRDMA              .equ $4014 
APUCTRL             .equ $4015 
JOY1                .equ $4016 


@@ 55,7 63,9 @@ CARDBUF1            .equ $0300
CARDBUF2            .equ $0340 
CARDBUF3            .equ $0380 
CARDBUF4            .equ $03c0 
	; variables

;; variables

	.enum $0000
hp@player               .dsb 1 ; health points
sp@player               .dsb 1 ; shield points


@@ 91,6 101,7 @@ lb@temp                 .dsb 1 ; utils
hb@temp                 .dsb 1 
id@temp                 .dsb 1 
damages@player          .dsb 1 ; TODO: check if necessary?
enabled@sound           .dsb 1 

;; TODO | cleanup


M src/init.asm => src/init.asm +1 -1
@@ 51,5 51,5 @@ loadPalette:                   ; [skip]

;; Run tests

	JSR Init@sound
	JSR Enable@sound
	; JSR run@tests

M src/main.asm => src/main.asm +16 -24
@@ 35,6 35,8 @@ checkJoy:                      ;
	BEQ onRight@splash
	CMP BUTTON_LEFT
	BEQ onLeft@splash
	CMP BUTTON_START
	BEQ onStart@splash
	CMP BUTTON_B
	BEQ onB@splash
	CMP BUTTON_A


@@ 47,6 49,8 @@ checkJoy:                      ;
	BEQ onLeft@game
	CMP BUTTON_SELECT
	BEQ onSelect@game
	CMP BUTTON_START
	BEQ onStart@game
	CMP BUTTON_B
	BEQ onB@game
	CMP BUTTON_A


@@ 54,34 58,18 @@ checkJoy:                      ;
	JMP __MAIN

onRight@splash:                ;
	INC cursor@splash
	LDA cursor@splash
	CMP #$03
	BNE @done
	; wrap around
	LDA #$00
	STA cursor@splash
@done:                         ;
	LDA #$01                     ; request draw for cursor
	STA reqdraw_cursor
	JSR MoveAlt@sound
	JSR NextDifficulty@splash
	JMP __MAIN

onLeft@splash:                 ;
	DEC cursor@splash
	LDA cursor@splash
	CMP #$FF
	BNE @done
	; wrap around
	LDA #$02
	STA cursor@splash
@done:                         ;
	LDA #$01                     ; request draw for cursor
	STA reqdraw_cursor
	JSR MoveAlt@sound
onLeft@splash:
	JSR PrevDifficulty@splash
	JMP __MAIN

onB@splash:                    ;
onStart@splash:                ;
	JSR Toggle@sound
	JMP __MAIN

onB@splash:
	LDA cursor@splash
	STA difficulty@player        ; store difficulty
	JSR show@game


@@ 127,6 115,10 @@ onSelect@game:                 ;
	JSR show@splash
	JMP __MAIN

onStart@game:                  ;
	JSR Toggle@sound
	JMP __MAIN

onB@game:                      ;
	JSR tryRun@player
	JMP __MAIN

M src/player.asm => src/player.asm +2 -0
@@ 95,6 95,7 @@ tryRun@player:                 ;
	BEQ @onEscape
	LDA #$04                     ; dialog: cannot_run when unable, display dialog
	JSR show@dialog
	JSR EscapeError@sound
	RTS 
@onEscape:                     ;
	JSR returnCards@room         ; draw cards for next room


@@ 103,6 104,7 @@ tryRun@player:                 ;
	STA has_run@player
	LDA #$0C                     ; dialog:run
	JSR show@dialog
	JSR Escape@sound
	RTS 
@onVictory:                    ;
	LDA #$00                     ; dialog:clear

M src/room.asm => src/room.asm +0 -1
@@ 61,7 61,6 @@ flipCard@room:                 ; (x:card_pos) ->
	; start timer
	LDA #$20                     ; timer length before running flipPost@room
	STA timer@room
	JSR Select@sound
@skip:
	RTS 


M src/sound.asm => src/sound.asm +135 -38
@@ 1,73 1,170 @@

;; Sound

Init@sound:
	LDA #%00000011               ; ch1 + ch2
Enable@sound:
	LDA #%00000111               ; ch1 + ch2 + ch3
	STA APUCTRL
	LDA #$01
	STA enabled@sound
	JSR Potion@sound
	LDA #$11                     ; dialog:sound-on
	JSR show@dialog
	RTS 

Disable@sound:
	; turn off
	LDA #%00000000               ; mute all
	STA APUCTRL
	LDA #$00
	STA enabled@sound
	LDA #$12                     ; dialog:sound-off
	JSR show@dialog
	RTS 

Toggle@sound:
	LDA enabled@sound
	CMP #$01
	BEQ Disable@sound
	JSR Enable@sound
	RTS 

Move@sound:
	PHA 
	LDA #%10011000
	LDA #%10011001
	STA APUCH1VOL
	LDA #$A9
	LDA #%11110001
	STA APUCH1SWP
	LDA #$d3
	STA APUCH1FRQ
	LDA #%00011010
	LDA #%01111001
	STA APUCH1LEN
	PLA 
	RTS 

MoveAlt@sound:
	PHA 
	LDA #%10011000
	LDA #%10011001
	STA APUCH1VOL
	LDA #$A9
	LDA #%11110001
	STA APUCH1SWP
	LDA #$e4
	STA APUCH1FRQ
	LDA #%00011011
	LDA #%01101001
	STA APUCH1LEN
	PLA 
	RTS 

Select@sound:
	PHA 
	LDA #%10011000
Enter@sound:
	LDA #%11011101
	STA APUCH1VOL
	LDA #%10111011
	STA APUCH1SWP
	LDA #$e4
	STA APUCH1FRQ
	LDA #%01101001
	STA APUCH1LEN
	RTS 

;; Items ch2

Shield@sound:                  ; $1ab = C3
	LDA #%11011101
	STA APUCH1VOL
	LDA #%10111010
	STA APUCH1SWP
	LDA #$c4
	STA APUCH1FRQ
	LDA #%01101001
	STA APUCH1LEN
	RTS 

ShieldError@sound:             ; $25c = G2#
	LDA #%10011001
	STA APUCH2VOL
	LDA #$31
	LDA #%11010111
	STA APUCH2SWP
	LDA #$92
	STA APUCH2FRQ
	LDA #%00011010
	LDA #%01101011
	STA APUCH2LEN
	PLA 
	RTS 

Enter@sound:
	PHA 
	LDA #%10011000
Potion@sound:                  ; $1ab = C3
	LDA #%10011001
	STA APUCH1VOL
	LDA #%11110001
	STA APUCH1SWP
	LDA #$34
	STA APUCH1FRQ
	LDA #%01101001
	STA APUCH1LEN
	RTS 

PotionError@sound:             ; $25c = G2#
	LDA #%10011001
	STA APUCH2VOL
	LDA #$21
	LDA #%10110101
	STA APUCH2SWP
	LDA #$92
	STA APUCH2FRQ
	LDA #%00111010
	LDA #%01101001
	STA APUCH2LEN
	PLA 
	RTS 

Error@sound:
	PHA 
	LDA #%10011000
;; Enemy ch4

EnemyGood@sound:               ; $3f8 = A2
	LDA #<$3f8
	STA APUCH4LEN
	LDA #>$3f8
	STA APUCH4FRQ
	LDA #%11000100
	STA APUCH4VOL
	RTS 

EnemyMedium@sound:             ; $389 = B2
	LDA #%11011101
	STA APUCH1VOL
	LDA #$A9
	LDA #%01101011
	STA APUCH1SWP
	LDA #$f4
	STA APUCH1FRQ
	LDA #%00011010
	LDA #%00111101
	STA APUCH1LEN
	PLA 
	RTS 

Cancel@sound:
	PHA 
EnemyBad@sound:                ; $326 = D2#
	LDA #%10011000
	STA APUCH1VOL
	LDA #$A9
	STA APUCH1FRQ
	LDA #%00011010
	STA APUCH1LEN
	PLA 
	STA APUCH2VOL
	LDA #%11010101
	STA APUCH2SWP
	LDA #$04
	STA APUCH2FRQ
	LDA #%01101001
	STA APUCH2LEN
	RTS 

;; Escape ch3

Escape@sound:                  ; $356 = C2
	LDA #<$356
	STA APUCH3FRQ
	LDA #>$356
	STA APUCH3LEN
	LDA #%00010000
	STA APUCH3CNT
	RTS 

EscapeError@sound:             ; $2ce = E2#
	LDA #<$2c3
	STA APUCH3FRQ
	LDA #>$2c3
	STA APUCH3LEN
	LDA #%00010000
	STA APUCH3CNT
	RTS 

Death@sound:                   ; $4b8 = G1#
	LDA #<$4b8
	STA APUCH3FRQ
	LDA #>$4b8
	STA APUCH3LEN
	LDA #%01111000
	STA APUCH3CNT
	RTS 

M src/splash.asm => src/splash.asm +30 -0
@@ 9,6 9,36 @@ show@splash:                   ;
	STA reqdraw_cursor
	RTS 

;; controls

NextDifficulty@splash:
	INC cursor@splash
	LDA cursor@splash
	CMP #$03
	BNE @done
	; wrap around
	LDA #$00
	STA cursor@splash
@done:                         ;
	LDA #$01                     ; request draw for cursor
	STA reqdraw_cursor
	JSR MoveAlt@sound
	RTS 

PrevDifficulty@splash:
	DEC cursor@splash
	LDA cursor@splash
	CMP #$FF
	BNE @done
	; wrap around
	LDA #$02
	STA cursor@splash
@done:
	LDA #$01                     ; request draw for cursor
	STA reqdraw_cursor
	JSR MoveAlt@sound
	RTS 

redrawCursor@splash:           ;
	; remove flag
	LDA #$00

M src/tables.asm => src/tables.asm +9 -5
@@ 170,7 170,7 @@ card4pos_low:                  ;

;; Dialog

dialogs:                       ; [skip]
dialogs:
	.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; clear 00
	.db $23,$33,$39,$00,$2a,$29,$29,$30,$00,$37,$2d,$27,$2f,$69,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; sickness 01
	.db $23,$33,$39,$36,$00,$37,$2c,$2d,$29,$30,$28,$00,$26,$36,$33,$2f,$29,$68,$00,$00,$00,$00,$00,$00 ; shieldbreak 02


@@ 188,18 188,22 @@ dialogs:                       ; [skip]
	.db $18,$33,$36,$31,$25,$30,$00,$6c,$00,$1d,$29,$30,$29,$27,$38,$00,$27,$25,$36,$28,$69,$00,$00,$00 ; normal mode 0e
	.db $12,$25,$36,$28,$00,$17,$33,$28,$29,$00,$6c,$00,$1d,$29,$30,$29,$27,$38,$00,$27,$25,$36,$28,$69 ; hard mode 0f
	.db $20,$2d,$27,$38,$33,$36,$3d,$00,$6d,$00,$16,$29,$25,$3a,$29,$00,$28,$39,$32,$2b,$29,$33,$32,$69 ; victory 10
	.db $1d,$33,$39,$32,$28,$37,$00,$19,$18,$3f,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; sound:ON 11
	.db $1d,$33,$39,$32,$28,$37,$00,$19,$10,$10,$3f,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; sound:OFF 12

;; dialogs map

dialogs_offset_low:            ;
dialogs_offset_low:
	.db #<(dialogs+(#$17* 0)),#<(dialogs+(#$17* 1)),#<(dialogs+(#$17* 2)),#<(dialogs+(#$17* 3)),#<(dialogs+(#$17* 4)),#<(dialogs+(#$17* 5))
	.db #<(dialogs+(#$17* 6)),#<(dialogs+(#$17* 7)),#<(dialogs+(#$17* 8)),#<(dialogs+(#$17* 9)),#<(dialogs+(#$17*10)),#<(dialogs+(#$17*11))
	.db #<(dialogs+(#$17*12)),#<(dialogs+(#$17*13)),#<(dialogs+(#$17*14)),#<(dialogs+(#$17*15)),#<(dialogs+(#$17*16))
	.db #<(dialogs+(#$17*12)),#<(dialogs+(#$17*13)),#<(dialogs+(#$17*14)),#<(dialogs+(#$17*15)),#<(dialogs+(#$17*16)),#<(dialogs+(#$17*17))
	.db #<(dialogs+(#$17*18))

dialogs_offset_high:           ;
dialogs_offset_high:
	.db #>(dialogs+(#$17* 0)),#>(dialogs+(#$17* 1)),#>(dialogs+(#$17* 2)),#>(dialogs+(#$17* 3)),#>(dialogs+(#$17* 4)),#>(dialogs+(#$17* 5))
	.db #>(dialogs+(#$17* 6)),#>(dialogs+(#$17* 7)),#>(dialogs+(#$17* 8)),#>(dialogs+(#$17* 9)),#>(dialogs+(#$17*10)),#>(dialogs+(#$17*11))
	.db #>(dialogs+(#$17*12)),#>(dialogs+(#$17*13)),#>(dialogs+(#$17*14)),#>(dialogs+(#$17*15)),#>(dialogs+(#$17*16))
	.db #>(dialogs+(#$17*12)),#>(dialogs+(#$17*13)),#>(dialogs+(#$17*14)),#>(dialogs+(#$17*15)),#>(dialogs+(#$17*16)),#>(dialogs+(#$17*17))
	.db #>(dialogs+(#$17*18))

;; cards


R tools/debug-zeropage.lua => tools/zeropage.lua +0 -0
A zeropage.lua => zeropage.lua +19 -0
@@ 0,0 1,19 @@
print("Added debugger!")

emu.speedmode("normal") -- Set the speed of the emulator

function printaddr(addr)
  res = string.format("%02x", memory.readbyte(addr) * 256):sub(1, -3)
  len = string.len(res)
  if len == 0 then return "00" elseif len <= 1 then return "0"..res else return res end
end

while true do
  for x=0,15 do 
    for y=0,15 do 
      id = x + (y * 16)
      gui.text((x * 15) + 10, (y * 10) + 15, printaddr(id))
    end
  end
  emu.frameadvance() 
end
\ No newline at end of file