Skip to content

Commit

Permalink
Displays correct total distance traveled on status bar
Browse files Browse the repository at this point in the history
References: AB#23
  • Loading branch information
samcan committed Jun 13, 2020
1 parent e5b2996 commit 81aa408
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 8 deletions.
Binary file modified src/bg_sprite0_traveling_screen.bin
Binary file not shown.
Binary file modified src/bg_sprite0_traveling_screen_rle.bin
Binary file not shown.
177 changes: 170 additions & 7 deletions src/engine_logic_functions.asm
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ EngineLogicTraveling:


LDA currframedy
BNE @DoneUpdatingMileage

BEQ @UpdateDay
JMP @DoneUpdatingMileage
@UpdateDay:
LDA #FRAMECOUNT_DAY
STA currframedy
Expand All @@ -110,25 +110,36 @@ EngineLogicTraveling:
STA tempcalca
MultiplyPercentageDistance tempcalca, pace, tempcalcb
LDA tempcalcb
STA mitraveldy

; update total mi traveled (this is a 16-bit number hence the rigamarole)
LDA mitraveled
CLC
ADC mitraveldy
STA mitraveled
STA bcdNum
LDA mitraveled+1
ADC #$00
STA mitraveled+1
STA bcdNum+1
JSR SixteenBitHexToDec

; time to trigger landmark?
; is miremaining <= mitraveled?
; is miremaining <= mitraveldy?
; if so, trigger landmark
LDA miremaining
CMP mitraveled
CMP mitraveldy
BCC @TriggerLandmark
BEQ @TriggerLandmark
SEC
SBC mitraveled
SBC mitraveldy
STA miremaining
JMP @DoneUpdatingMileage

@TriggerLandmark:
LDA #$00
STA miremaining


@DoneUpdatingMileage:
LDX #$24
JSR UpdateStatusIcons
Expand Down Expand Up @@ -574,6 +585,118 @@ UpdateStatusIcons:
LDA #$50+$68
STA $0200, x
INX

MileageTraveled:
; total mileage traveled
LDA #$00
STA thousshown
STA hundsshown

; display thousands
LDA bcdResult+3
BEQ @ThousandsNotShown
JMP @ThousandsShown
@ThousandsNotShown:
LDA #$00
TAY
JMP @ContThousands
@ThousandsShown:
CLC
ADC #$44
TAY
LDA #$01
STA thousshown
@ContThousands:
LDA #STATUS_ICON_Y + $20
STA $0200, x
INX
TYA
STA $0200, x
INX
LDA #%00000001
STA $0200, x
INX
LDA #$50+$50
STA $0200, x
INX

@DisplayHundreds:
; display hundreds
LDA bcdResult+2
BEQ @HundredsZero
JMP @HundredsShown
@HundredsZero:
LDA thousshown
BEQ @HundredsNotShown
JMP @HundredsShown
@HundredsNotShown:
LDA #$00
TAY
JMP @ContHundreds
@HundredsShown:
LDA #$01
STA hundsshown
LDA bcdResult+2
CLC
ADC #$44
TAY
@ContHundreds:
LDA #STATUS_ICON_Y + $20
STA $0200, x
INX
TYA
STA $0200, x
INX
LDA #%00000001
STA $0200, x
INX
LDA #$50+$58
STA $0200, x
INX

; display tens
LDA #STATUS_ICON_Y + $20
STA $0200, x
INX
LDA bcdResult+1
BEQ @TensZero
@TensNotZero:
LDA bcdResult+1
CLC
ADC #$44
JMP @ContTens
@TensZero:
LDA thousshown
ORA hundsshown
BNE @TensNotZero
LDA #$00
@ContTens:
STA $0200, x
INX
LDA #%00000001
STA $0200, x
INX
LDA #$50+$60
STA $0200, x
INX
; now we'll display ones, which are easy because we always display the
; ones place
LDA bcdResult
CLC
ADC #$44
PHA
LDA #STATUS_ICON_Y + $20
STA $0200, x
INX
PLA
STA $0200, x
INX
LDA #%00000001
STA $0200, x
INX
LDA #$50+$68
STA $0200, x
INX
RTS
;;;;;;;;;;;;;;;;
EightBitHexToDec:
Expand Down Expand Up @@ -618,4 +741,44 @@ EightBitHexToDec:
JMP htd1$ ; NMOS 6502 can use JMP.

htd3$: STY htd_in ; Restore the original input.
RTS
RTS
;;;;;;;;;;;;;;;
SixteenBitHexToDec:
; from http://forums.nesdev.com/viewtopic.php?f=10&t=1222&start=15 by tokumaru
BinToDec:
LDA #$00
STA bcdResult+0
STA bcdResult+1
STA bcdResult+2
STA bcdResult+3
STA bcdResult+4
LDX #$10
BitLoop:
ASL bcdNum+0
ROL bcdNum+1

LDY bcdResult+0
LDA Table, y
ROL
STA bcdResult+0

LDY bcdResult+1
LDA Table, y
ROL
STA bcdResult+1

LDY bcdResult+2
LDA Table, y
ROL
STA bcdResult+2

LDY bcdResult+3
LDA Table, y
ROL
STA bcdResult+3

ROL bcdResult+4

DEX
BNE BitLoop
RTS
14 changes: 13 additions & 1 deletion src/westward.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ gamestate .dsb 1 ; current game state
newgmstate .dsb 1 ; new game state
buttons1 .dsb 1 ; player 1 controller buttons pressed
miremaining .dsb 1 ; number of miles remaining (in curr. segment of map)
mitraveled .dsb 1 ; number of miles traveled (curr. day)
mitraveldy .dsb 1 ; number of miles traveled (curr. day)
mitraveled .dsb 2 ; number of miles traveled (total)
yokeoxen .dsb 1 ; number of yoke of oxen
pace .dsb 1 ; travel pace (steady, strenuous, grueling)
curlandmark .dsb 1 ; current landmark we're traveling toward (index value)
Expand Down Expand Up @@ -50,7 +51,10 @@ tempcalca .dsb 1
tempcalcb .dsb 1
htd_in .dsb 1
htd_out .dsb 2
thousshown .dsb 1
hundsshown .dsb 1
bcdNum .dsb 2
bcdResult .dsb 5
.ende

;; DECLARE CONSTANTS HERE
Expand Down Expand Up @@ -321,7 +325,12 @@ SetInitialState:
; set the number of miles traveled in the current segment to 0 mi.
LDA #$00
STA mitraveldy

; set total miles traveled to 0
LDA #$00
STA mitraveled
STA mitraveled+1

; set index 0 as the initial landmark traveling towards
LDA #$00
Expand Down Expand Up @@ -479,6 +488,9 @@ daytext:
.db $47, $44 ; 30
.db $47, $45

Table:
.db $00, $01, $02, $03, $04, $80, $81, $82, $83, $84

.org $FFFA ;first of the three vectors starts here
.dw NMI ;when an NMI happens (once per frame if enabled) the
;processor will jump to the label NMI:
Expand Down

0 comments on commit 81aa408

Please sign in to comment.