It is currently Sat Oct 21, 2017 3:41 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Apr 16, 2015 6:49 am 
Offline

Joined: Mon Feb 23, 2015 8:05 pm
Posts: 11
I know that games swap parts of the character table by bankswitching. But I want to only replace a few tiles in my code. Is this possible?
I'm hacking a menu rom that I have, so it's hard to show all the code. But this is what I came up with which does not seem to do the trick:

Code:
 PHA
 TYA
 PHA
 TXA
 PHA

 LDA $0653
 CMP $0C00
 BEQ NoChange
 STA $0C00

 LDA $2002
 LDA #$06
 STA $2006
 LDA #$7F
 STA $2006

 LDX #$00
MoreBytes:
 LDA $8100,X
 STA $2007
 INX
 CPX #$00
 BNE MoreBytes

NoChange:
 PLA
 TAX
 PLA
 TAY
 PLA


what I'm trying to do here is
- check if $0653 has changed
- If changed, then Copy 256 bytes from $8100 to tile 68+ in table 1

Right now it does do something, but it messes up stuff and the result is not right.
(btw, I know I could count down and leave away the cmp, but this is only dummy code to get things working)


Top
 Profile  
 
PostPosted: Thu Apr 16, 2015 7:17 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7232
Location: Chexbres, VD, Switzerland
This is possible if you use CHR-RAM, but then you have to load all pattern graphics yourself in the RAM. On the other hand, if you use CHR-ROM it is not possible to write to it, but you can have another bank which changes only a few characters (this is a huge waste - but still technically possible).


Top
 Profile  
 
PostPosted: Thu Apr 16, 2015 8:15 am 
Offline

Joined: Mon Feb 23, 2015 8:05 pm
Posts: 11
Thank you for the reply.

I've been looking some more into it, and it seems to work now for a few tiles. But when I copy too many the screen shifts and things mess up.
I'm thinking it has something to do with it taking too long and exiting v-blank.
If this is the case, can I dissable the screen from redrawing during my copying and sync on the next frame?
if so, how would you do this?


Top
 Profile  
 
PostPosted: Thu Apr 16, 2015 8:34 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7232
Location: Chexbres, VD, Switzerland
When writing a bunch of large data to VRAM, always do it by turning the screen off (write $00 to $2001). When turning the screen on, be sure to write proper scroll values to $2005, because writing to $2006 (which is necessary to write to VRAM) uses the same counters internally and will change the scroll.

Example of what it could look like :
Code:
   lda #$00
   sta $2000
   sta $2001   ; No VBL NMI, turn screen off

....           ; Your loop copies data to VRAM here

- bit $2002    ; Wait for the start of a VBlank (it avoid getting a "bad frame" when you turn screen on
  bpl -        ;- but many commercial games have this bug
              ; Turn rendering on again
  lda #$88    ; Or whathever value you wish to use
  sta $2000
  lda #$1e    ; Or whathever value you wish to use
  sta $2001


Top
 Profile  
 
PostPosted: Thu Apr 16, 2015 9:08 am 
Offline

Joined: Mon Feb 23, 2015 8:05 pm
Posts: 11
Great! this does it for now.
I assume there is no way to prevent the flicker during the swapping because we turn the screen off.
But that's not too bad.
Thank you for the great help.


Top
 Profile  
 
PostPosted: Thu Apr 16, 2015 12:02 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19113
Location: NE Indiana, USA (NTSC)
If you don't want the flicker, you can update the tiles gradually at about eight tiles per vblank.


Top
 Profile  
 
PostPosted: Thu Apr 16, 2015 3:03 pm 
Offline

Joined: Mon Feb 23, 2015 8:05 pm
Posts: 11
I was thinking about doing that. Thank you for confirming it to be a good idea. I'm patching the rom byte by byte with opcodes so I wasn't sure if it was worth the effort. But now I might go for it next time I feel like putting some more work in that routine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group