From 637764ff28ef2d872d5e8243d28ed557691d69ad Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sun, 4 Nov 2012 13:25:11 -0500 Subject: [PATCH] Made oamInsertMultiSprite a real function, just needs a list of actors to stop using $0200 now --- defines.S | 16 +++++++++++++- nesgame.S | 66 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/defines.S b/defines.S index bdf46f7..145fee7 100644 --- a/defines.S +++ b/defines.S @@ -1,2 +1,16 @@ .alias curSpriteDataRead curSpriteDataLo - .alias curSpriteDataWrite curSpriteDataHi \ No newline at end of file + .alias curSpriteDataWrite curSpriteDataHi + +.macro storeStackReturn ; storeStackReturn + PLA + STA prevReturnAddrHi + PLA + STA prevReturnAddrLo +.macend + +.macro restoreStackReturn + LDA prevReturnAddrLo + PHA + LDA prevReturnAddrhi + PHA +.macend \ No newline at end of file diff --git a/nesgame.S b/nesgame.S index 36a7d44..65c89a6 100644 --- a/nesgame.S +++ b/nesgame.S @@ -15,13 +15,20 @@ .include "defines.S" - .text zp ; zero page - this begins at $00 - ; all pointers should go here - ;; $0000 - $000F is reserved for local variables/function args - .org $0010 ; $0010 - 002F reserved for pointers + .text zp + .org $0000 + ;; $0000 is reserved for things we use to extend PL/PH for call/return stacks + ;; FIXME: Will need to expand this stuff once I start calling 2+ + ;; functions at once; e.g., JSR a -> JSR b -> JSR c... + ;; will need to expand it to a real stack. + .space prevReturnAddrLo 1 + .space prevReturnAddrHi 1 + .org $0010 + ;; $0010 - 001F is reserved for global pointers .space curSpriteDataLo 1 .space curSpriteDataHi 1 - .org $0030 + .org $0020 + ;; $0020 - 00FF is space for general purpose global variables .space curSpriteLen 1 .space playery 1 .space playerx 1 @@ -193,22 +200,45 @@ _MAIN_LoadPaletteLoop: LDA #$80 STA playerx STA playery + ;; Put mario in as the first multisprite + LDA #sprMarioData + PHA + LDA sprMario + PHA + ;; DO IT + JSR oamInsertMultiSprite _MAIN_loop: JMP _MAIN_loop ;; Loop forever -NMI: + ;; Function : oamInsertMultiSprite + ;; + ;; Given the address of a multisprite, and its length (number of + ;; subsprites), load the multisprite into the OAM memory at + ;; index 0. + ;; + ;; Arguments on the stack: + ;; - Length of multisprite + ;; - High byte of multisprite's address + ;; - Low byte of multisprite's address + ;; + ;; FIXME: Need to keep a list of all multisprites so I can append + ;; new ones to the list, and remove dead ones; right now this all + ;; presumes $0200 is the root for the multisprite, which will stop + ;; being true once I have more than one. +oamInsertMultiSprite: + .invoke storeStackReturn LDX #$0 LDY #$0 - ;; This is almost a reusable function ... store 'sprMario' as our - ;; current sprite that we're about to draw - LDA sprMario + PLA STA curSpriteLen - LDA #>sprMarioData + PLA STA curSpriteDataHi - LDA #