Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Routine to change multiple hex numbers to decimal in order to display them on the screen
- ; This is a modified version of the Nerdy Nights tutorial on the same subject. See here:
- ; http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308
- ; This routine is zeropage heavy, but is being used for an RPG-style game, so it is a lot
- ; of what the game is related to. If you can't use as much zeropage as this, then at the
- ; very least the reserved bytes with the ";;" following them is a must to run this code
- ; properly.
- ; ZEROPAGE
- temp_8bit_1: .res 1
- ones_prelim: .res 1
- tens_prelim: .res 1
- hp_han: .res 1
- hp_hubs: .res 1
- hp_hekl: .res 1
- mp_han: .res 1
- mp_hubs: .res 1
- mp_hekl: .res 1
- attack_han: .res 1
- attack_hubs: .res 1
- attack_hekl: .res 1
- defense_han: .res 1
- defense_hubs: .res 1
- defense_hekl: .res 1
- speed_han: .res 1
- speed_hubs: .res 1
- speed_hekl: .res 1
- han_tens_hp: .res 1 ;;
- hubs_tens_hp: .res 1 ;;
- hekl_tens_hp: .res 1 ;;
- han_ones_hp: .res 1 ;;
- hubs_ones_hp: .res 1 ;;
- hekl_ones_hp: .res 1 ;;
- han_tens_mp: .res 1 ;;
- hubs_tens_mp: .res 1 ;;
- hekl_tens_mp: .res 1 ;;
- han_ones_mp: .res 1 ;;
- hubs_ones_mp: .res 1 ;;
- hekl_ones_mp: .res 1 ;;
- han_tens_att: .res 1 ;;
- hubs_tens_att: .res 1 ;;
- hekl_tens_att: .res 1 ;;
- han_ones_att: .res 1 ;;
- hubs_ones_att: .res 1 ;;
- hekl_ones_att: .res 1 ;;
- han_tens_def: .res 1 ;;
- hubs_tens_def: .res 1 ;;
- hekl_tens_def: .res 1 ;;
- han_ones_def: .res 1 ;;
- hubs_ones_def: .res 1 ;;
- hekl_ones_def: .res 1 ;;
- han_tens_spd: .res 1 ;;
- hubs_tens_spd: .res 1 ;;
- hekl_tens_spd: .res 1 ;;
- han_ones_spd: .res 1 ;;
- hubs_ones_spd: .res 1 ;;
- hekl_ones_spd: .res 1 ;;
- ; Do this in the loop somewhere...
- ldy #$00
- sty tens_prelim
- sty ones_prelim
- jsr player_conv
- ; ... and here is the subroutine
- ; INITIALIZE 'Y' REGISTER AND ONES_ AND TENS_
- ; PRELIM TO 0 BEFORE CALLING THIS ROUTINE
- player_conv:
- lda hp_han, y ; Load A with character stat
- sta temp_8bit_1 ; Store it in temp to preserve character stat in RAM
- @next_player_conv: ; because the temp will be changed by end of routine
- lda temp_8bit_1 ; Must load temp again because of looping
- cmp #$0a ; Compare temp to decimal 10
- bcc @do_ones ; If it's less than 10, branch to the ones
- lda temp_8bit_1 ; If not, subtract by ten to get the number
- sec ; widdled down to a single digit.
- sbc #$0a ;
- sta temp_8bit_1 ;
- inc tens_prelim ; Increment tens_prelim each iteration to create single digit for tens spot
- jmp @next_player_conv ; Jump back to see if we need to subtract by 10 again
- @do_ones:
- lda temp_8bit_1 ; Load A with temp again and store it in ones_prelim
- sta ones_prelim ; since number is already a single digit
- ldx hex_tens_prelim, y ; Load X with the table hex_tens_prelim offset by Y for using
- lda tens_prelim ; the zeropage tables
- clc ; Clear the carry to ready for addition
- adc #$30 ; Add #$30 to the tens_prelim to adjust tile number for showing
- sta $00, x ; digit on-screen and store into correct zeropage RAM slot
- ldx hex_ones_prelim, y ; Load X with the table hex_ones_prelim offset by Y for using
- lda ones_prelim ; the zeropage tables
- clc ; Clear the carry to ready for addition
- adc #$30 ; Add #$30 to the ones_prelim to adjust tile number for showing
- sta $00, x ; digit on-screen and store into correct zeropage RAM slot
- lda #$00 ; Clear ones_prelim and tens_prelim to prepare them for use
- sta tens_prelim ; on the next character stat to be used in the loop
- sta ones_prelim ;
- iny ; Increment Y and check if has reached decimal 15 yet
- cpy #$0f ; If it hasn't, then branch back to player_conv and run
- bne player_conv ; the hex to decimal routine again
- rts ; Return when loop is complete
- ; Zeropage tables for use of storing the digits. These variables are the
- ; ones necessary to be in ZP for the code to run properly
- hex_tens_prelim:
- .byte <han_tens_hp,<hubs_tens_hp,<hekl_tens_hp
- .byte <han_tens_mp,<hubs_tens_mp,<hekl_tens_mp
- .byte <han_tens_att,<hubs_tens_att,<hekl_tens_att
- .byte <han_tens_def,<hubs_tens_def,<hekl_tens_def
- .byte <han_tens_spd,<hubs_tens_spd,<hekl_tens_spd
- hex_ones_prelim:
- .byte <han_ones_hp,<hubs_ones_hp,<hekl_ones_hp
- .byte <han_ones_mp,<hubs_ones_mp,<hekl_ones_mp
- .byte <han_ones_att,<hubs_ones_att,<hekl_ones_att
- .byte <han_ones_def,<hubs_ones_def,<hekl_ones_def
- .byte <han_ones_spd,<hubs_ones_spd,<hekl_ones_spd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement