Originally posted by: MadnessVX
I took a look at your drawing routine, and I was having trouble understanding what was happening. The syntax is probably throwing me off as well. If it's fine, could you sort of explain what each routine is doing or describe the flow of the program? Thanks for sharing it by the way!
Disclaimer: I am not an expert NES programmer, I'm new to NES development, this is not a solution but it is actually a problem since the unresolved flickering issue, however it works, and you are asking about it. But you likely better ask better advice to more experienced and skilled NES programmers. I use this because of the lack of better alternatives.
Continue reading at your own risk!
Above !f000 Code there are only lookup tables and data stored.
Exiting the NMI (rti) you can have x = 00 or x = ff
If x = ff then go to SET then loop (exiting SET x = 00).
In set if
mode = 02 then it's Dialog Mode (also named "text" or "talk").
In talk mode there is only a Sprite on screen and the background has a frame and two lines of text of 20 char each. Ldx 55 it's for the attribute (which in my last version can be also AA or FF). All the background has the same attribute which means only 3 BKG colors (+black transparency) are visible on a full screen of bkg.
jsr <sprTalk
ldx 40 jsr <Empty
jsr <Header
ldy 07 jsr <Frame
ldx 00 jsr <TextLine
ldy 01 jsr <Frame
ldx 01 jsr <TextLine
ldy 0d jsr <Frame
jsr <Footer
ldx 80 jsr <Empty
ldx 55
I believe the frame part is quite understandable. And however, it's about the frame, not the text display routine.
TextLine maybe a bit less obvious.
>TextLine
lda <text asl $
cpx 00 bne <line+
tax lda <Line-,x sta <lo
inx lda <Line-,x sta <hi
>findpage
ldx <page beq <print
> lda <lo clc adc 14 sta <lo
lda <hi adc 00 sta <hi dex bne <
>print
jsr <FrameL+
ldx 04 jsr <Empty
ldy 00 > b1 <lo sta $2007
iny cpy 14 bne <
ldx 04 jsr <Empty
jsr <FrameR-
rts
>line+
tax lda <Line+,x sta <lo
inx lda <Line+,x sta <hi
jmp <findpage
First take the text number id to be shown, stored in "text" address.
FI for the intro it is 00.
Multiply x2 (addresses are 2 bytes!).
Check if it is the first or second line (- or +).
Save address: low byte, increment by one, and save high byte from the correct lookup table (- or +).
If the variable page (lower p) is 0 start from the beginning of the text, add 20 (14 HEX) bytes of text for each page already shown before (check out NN 16bit math).
Now, if this is confusing, you are right, I apologize for missing explaining this before:
ldy 00 > b1 <lo sta $2007
iny cpy 14 bne <
I didn't put indirect/indexed indexed/indirect addressing in my assembler, but since I would use LDA (foo),y and I know the opcode is b1, I just write b1 <foo .
Also in my syntax
>foo means for the assembler: "store this address you are right now as foo", while
<foo means "at address stored as foo".
Hence: b1 <foo == LDA (foo),y
Once you know the starting address, just copy 20 (14 HEX) bytes.
Exiting SET make sure x = 00 and you get back into the main loop.
In NMI, when in mode 02:
>KeyA cmp 08 bne <Exit
cmp <key- beq <Exit ; TALK mode (02): if key = 8 (A) and key+ != key-
ldx <page inx stx <page
lda <page ldx <text ; switch to WALK Mode (01) if page = Page
cmp <Page,x bne <text+ ; else go to the next page TEXT GO ONE PAGE FORWARD
lda 01 sta <mode
ldx 00 stx <page
>text+
ldx ff bne <Exit
If the KeyA (button A) is pressed, and it wasn't pressed the previous NMI, the variable page += 1.
If the number of pages (taken from the lookup table Page) equals the variable page all the text has been shown, set the mode to 01 (explore) and the page to 00. Else keep the mode as 02 and it will show the next page.
In both cases x = ff because you want to run SET again.
I hope this helps, if you need more details about something let me know.
By the way, in my syntax:
*23,key+
means that the address in zeropage $23 can be loaded and stored with <key+ .
*0200,sprite
means that the address $0200 can be loaded and stored with <sprite .
I like to have control over the ram (mostly zeropage) addresses also for debug purposes (check the HexDebug in FCEux), but I like to use text label as key+ rather than remember that $23 is for the last button pushed.
asl $
(without a hex numeric address) means asl on the accumulator.
Last notes
Hex values does not have #$. If you see 14, it is HEX 14 (hence 20 decimal).
Values with $ are addresses: $00 zeropage, $2001 direct, $0200,x indirect.
Ah... and you can write several instruction on the same line!
---
Cheers!
- user