|
Post by siudym on Nov 28, 2021 14:44:02 GMT
Hello.
I have a problem with the code. The function copies BAT (nametable) to VRAM at $ 0000. The source binary file has 1024 bytes, so each byte copied is written into the LO VRAM byte and the HI byte is written to the value specified in LDX (value $ 05).
(A nametable copying loop ends with the detection of a pointer FF byte)
I would like nametable to be loaded only into VRAM LO byte and HI byte omitted completely.
The current code copies nametable binary (1024b) into LO VRAM bytes and Hi inserts # $ 05
LoadBAT:
LDA #LOW(NameTable) ; nametable (tilemap) / BAT source (1024 bytes binary)
STA <SrcAddrLO
LDA #HIGH(NameTable)
STA <SrcAddrHI
LDA #LOW($0000) ; vram nametable address destination
STA <DscAddrLO
LDA #HIGH($0000)
STA <DscAddrHI
LDA #$00
STA $0000 ; GPU Reg Select (ST0)
STA $20F7
LDA <DscAddrLO
STA $0002 ; video_data / video_data_l / GPU Data L (ST1) (IO Ports)
LDA <DscAddrHI
STA $0003 ; video_data+1 / video_data_h GPU Data H (ST2) (IO Ports)
LDA #$02
STA $0000
STA $20F7
CLY
ldx #5
LoadBAT_Loop:
LDA [SrcAddrLO],Y
CMP #$FF ; stops copying BAT when it detects an FF value
BEQ LoadBAT_Finish
STA $0002 ; video_data / video_data_l
STX $0003 ; video_data+1 / video_data_h
inc <SrcAddrLO
bne .skip
inc <SrcAddrHI
.skip:
JMP LoadBAT_Loop
LoadBAT_Finish:
RTS
;---------------------------------
NameTable:
.incbin "demo.nam" ; 1024 b
|
|
|
Post by dshadoff on Nov 28, 2021 15:46:07 GMT
But why do want to omit the high byte completely ?
*Something* must be written into the high byte, as this will cause the auto-increment of the address (and probably affects the latching of the low value as well). If you must not alter the high byte, you will need to already know what that is, and rewrite it.
|
|
|
Post by turboxray on Nov 28, 2021 21:38:16 GMT
Hello. I have a problem with the code. The function copies BAT (nametable) to VRAM at $ 0000. The source binary file has 1024 bytes, so each byte copied is written into the LO VRAM byte and the HI byte is written to the value specified in LDX (value $ 05). (A nametable copying loop ends with the detection of a pointer FF byte) I would like nametable to be loaded only into VRAM LO byte and HI byte omitted completely. The current code copies nametable binary (1024b) into LO VRAM bytes and Hi inserts # $ 05 Nametable? You're coming from NES dev I take it? So you only want to update the LSB of the BAT word? And don't want to write the "#immediate" of the MSB? You can do: lda $0003 sta $0003
Just make sure you have setup the Read pointer to match the Write pointer before your loop. If you want to be fancy,,, cla tsb $0003
Saves a couple of cycles. But just an FYI.. since you always have to write a WORD to vram, and in your EXAMPLE the MSB VALUE was fixed (or vice versa), you can use ST2 #$05. Or ST1 for LSB. It saves some cycles and a reg. Another FYI - while reads and writes to VRAM have to be WORD values. But even though all the VDC registers are 16bit or WORD - you don't have to write the full WORD value.. just the LSB or just the MSB works fine for that.
|
|
|
Post by siudym on Nov 29, 2021 12:59:09 GMT
Yes, mostly NES.
Are there any PSG Audio library for music and sound effects? For use in code.
Back to the topic: I solved the problem. I wanted to use an additional function that previously stored the pallet number (palette array) in HI bytes. That's why I wanted this function not to interfere with HI byte. It made no sense. Now I wrote a function that does all of this simultaneously - it both writes a table of tiles and an table of used palettes to VRAM:
LoadBAT:
LDA #LOW(NameTable) ; nametable (tilemap) / BAT source (1024 bytes binary) STA <SrcAddrLO LDA #HIGH(NameTable) STA <SrcAddrHI
LDA #LOW($0000) ; vram nametable address destination STA <DscAddrLO LDA #HIGH($0000) STA <DscAddrHI
LDA #LOW(ColorTable) STA <CTLoadLO LDA #HIGH(ColorTable) STA <CTLoadHI
LDA #$00 STA $0000 ; GPU Reg Select (ST0) STA $20F7
LDA <DscAddrLO STA $0002 ; video_data / video_data_l / GPU Data L (ST1) (IO Ports) LDA <DscAddrHI STA $0003 ; video_data+1 / video_data_h GPU Data H (ST2) (IO Ports)
LDA #$02 STA $0000 STA $20F7
LoadBAT_Loop:
LDA [CTLoadLO] TAX
LDA [SrcAddrLO] CMP #$FF ; stops copying BAT when it detects an FF value BEQ LoadBAT_Finish
STA $0002 ; video_data / video_data_l STX $0003 ; video_data+1 / video_data_h
INC <SrcAddrLO BNE LoadBAT_Skip INC <SrcAddrHI
LoadBAT_Skip:
BRA LoadBAT_Loop
LoadBAT_Finish: RTS
;---------------------------------
NameTable: .incbin "nametable.nam" ; 896 bytes table (32x28 tile array) ColorTable: .incbin "colortable.nam" ; 896 bytes table (32x28 palette array)
The color table writes values every $10 bytes + $5 correction in lower nibble because in this case the background tiles are at $5000 VRAM:
; pal00=$05 ; pal01=$15 ; pal02=$25 ; pal03=$35 ; pal04=$45 ; pal05=$45 ; pal06=$55 ; pal07=$65 ; pal08=$75 ; pal09=$85 ; pal10=$A5 ; pal11=$B5 ; pal12=$C5 ; pal13=$D5 ; pal14=$E5 ; pal15=$F5
|
|
|
Post by siudym on Dec 6, 2021 11:20:41 GMT
In PCE, the sprite position on the corner of the screen, e.g. TOP-LEFT, is not in the Y.$00 / X.$00 as in the case of NES, but it is Y. $ 40 / X. $ 20 - is it possible to set the screen in such a way that the sprite zero position is corner was Y00, X00?
|
|
|
Post by turboxray on Dec 6, 2021 15:17:14 GMT
In PCE, the sprite position on the corner of the screen, e.g. TOP-LEFT, is not in the Y.$00 / X.$00 as in the case of NES, but it is Y. $ 40 / X. $ 20 - is it possible to set the screen in such a way that the sprite zero position is corner was Y00, X00? No. No matter what you set the screen size to (dimensions), it will always be that. And the reason why is because you want to be able to have a cell of a meta sprite because to come on screen from the left and top without it 'popping'. 32x64 is the largest size SAT cell, so that's where those numbers come from.
For my code, my sprite positions, attributes, etc are not my literal SAT entries. I translate my sprites to SAT entries every frame. I have meta sheet table entries for translations (which a lot of NES games did as well. Megaman comes to mind).
|
|
|
Post by siudym on Dec 6, 2021 15:59:23 GMT
And the reason why is because you want to be able to have a cell of a meta sprite because to come on screen from the left and top without it 'popping'. 32x64 is the largest size SAT cell, so that's where those numbers come from. I figured that was the reason. Of course, I have no major problems - In my code, I always subtract # $ 20 and # $ 40 so that the calculations are always perfectly within the width of the visible one screen (I do not need to extend the sprite beyond the screen). However, I thought there was such a graphics mode.
|
|
|
Post by dshadoff on Dec 6, 2021 16:45:33 GMT
No, the PC Engine isn't a machine full of exceptions to the extent of other systems of that era.
|
|
|
Post by Galahad on Dec 6, 2021 17:33:23 GMT
Off topic but any plans to port Micro Knight over to pce?Had fun playing the nes version.
|
|