Videopac / Odyssey2 forum
November 20, 2019, 12:22:55 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Join Rafael's Haunted Woods contest and win a copy of the game!
 
   Home   arcade Help Login Register links videopac.nl  
Pages: [1]   Go Down
  Print  
Author Topic: Multiplexing sprites / quads  (Read 1679 times)
Mux
Trying to get the cartridge in...
*
Posts: 40



« on: April 30, 2019, 10:21:32 PM »

Hey everyone!

I know this has been done to death but I can't find anything that cohesively ties it nicely together. I'm trying to multiplex a single sprite. Nothing big, just a proof of concept. Ideally I'd like to use a timer interrupt but to simplify things, I started off wasting valuable CPU time and wait for a specific line and then change a color.

So far, so good. Color changes accordingly but for some reason I never get to change the sprite's Y coordinate.

In pseudocode:

loop
call waitvsync
call gfxon
set background color to blue
set sprite y-position to 50
wait for line 75
set background color to red
set sprite y-position to 100
goto loop

For some reason the sprite only shows the last position (100). There's ample time between the old position (50) and the new position (100). I get the same result if I use a timer interrupt. What am I missing?

Thanks!

-Mux
Logged
Mux
Trying to get the cartridge in...
*
Posts: 40



« Reply #1 on: May 01, 2019, 03:56:55 AM »

Figured I'd knock up a small interrupt based one to illustrate the problem. Simple example with color and multiplexing one sprite. You can see the sprite for the first frame in the blue section and then (after the interrupt) only in the red section.

I use as48 from Kingswood btw as it runs on 32/64 bit windows. You can download it here:

http://www.kingswood-consulting.co.uk/assemblers/

and here's the (non multiplexing) code:
Code:
code
org $400

include "g7000.i"

jmp selectgame ; RESET
jmp irq ; interrupt
jmp timer_irq ; timer
jmp vsyncirq ; VSYNC-interrupt
jmp start_game ; after selectgame
jmp soundirq ; sound-interrupt

; timer interrupt fires once at line 64.
; the next line interrupt will fire 256 from now, at which point we'll have reset it
timer_irq:
sel rb0
mov r7,a ; save accumulator
in a,p1
mov r6,a ; save p1
stop tcnt

call vdcenable

; set new color
mov r0,#vdc_color
mov a,#col_bck_red
movx @r0,a

; set sprite y-pos to 100
mov r0,#vdc_spr0_ctrl
mov a,#100
movx @r0,a

timer_irq_exit:
mov a,r6
outl p1,a
mov a,r7
sel rb1
retr

start_game:
call gfxoff

; initialize sprite @(32,32), white
mov r0,#vdc_spr0_ctrl
mov a,#32
movx @r0,a
inc r0
mov a,#32
movx @r0,a
inc r0
mov a,#col_spr_white
movx @r0,a

; set shape
mov r0,#vdc_spr0_shape
mov r1,#8
mov a,#255
init_sprite0_loop:
movx @r0,a
inc r0
djnz r1,init_sprite0_loop

main_loop:
; wait for beginning of frame...
call waitvsync
call gfxoff ; disable VDC access

; set sprite y-pos to 32
mov r0,#vdc_spr0_ctrl
mov a,#32
movx @r0,a

; and move it across the screen so we know we haven't crashed yet :-)
inc r0
movx a,@r0
inc a
movx @r0,a

; starting color
mov r0,#vdc_color
mov a,#col_bck_blue
movx @r0,a

; start timer
mov a,#255-64
mov t,a
start t
en tcnti

; turn graphics on
call gfxon

jmp main_loop

; force to 2048 rom size
org $bff
db 0

end

Thanks so much for any insight. I realize this has been done multiple times over but there are only snippets that get into it..

Thanks!

-Mux
« Last Edit: May 01, 2019, 04:08:31 AM by Mux » Logged
TedFoolery
Played Munchkin once...
**
Posts: 75


« Reply #2 on: May 01, 2019, 05:00:27 PM »

If I have time I can try it out tonight. My first thought though is you might be better offer writing your own vysnc interrupt and setting the first sprites there.
Logged
Mux
Trying to get the cartridge in...
*
Posts: 40



« Reply #3 on: May 01, 2019, 06:34:11 PM »

Thanks!

Does it make that much of a difference though? The sprite positioning is pretty low down so any / all vblank code should have executed.. Moving the sprites down to allow for more time doesn't make a difference either..

The search goes on!

-Mux
Logged
TedFoolery
Played Munchkin once...
**
Posts: 75


« Reply #4 on: May 02, 2019, 04:12:34 AM »

Mux, got it working. The issue is, just like in the main loop, you have to turn off the gfx before writing to the vdc (then turn them back on when done). There is a problem though. The gfxoff and gfxon bios functions have other things going on which makes them not work during the ira, so we have write our own.
Also, I had to move the interrupt line down more.

Code:
code
org $400

include "g7000.i"

jmp selectgame ; RESET
jmp irq ; interrupt
jmp timer_irq ; timer
jmp vsyncirq ; VSYNC-interrupt
jmp start_game ; after selectgame
jmp soundirq ; sound-interrupt

; timer interrupt fires once at line 64.
; the next line interrupt will fire 256 from now, at which point we'll have reset it
timer_irq:
sel rb0
mov r7,a ; save accumulator
in a,p1
mov r6,a ; save p1
stop tcnt

call vdcenable
;turn off gfx (4 lines)
mov r0,#0a0h
movx a,@r0                    ; read $A0 VDC Control Register
anl a,#0d6h                       ; Turn off foreground,grid
movx @r0,a

; set new color
mov r0,#vdc_color
mov a,#col_bck_red
movx @r0,a

; set sprite y-pos to 100
mov r0,#vdc_spr0_ctrl
mov a,#100
movx @r0,a

;turn gfxon (4 lines)
mov r0,#0a0h
movx a,@r0
orl a,#028h                       ; set Foreground,Grid on
movx @r0,a


timer_irq_exit:
mov a,r6
outl p1,a
mov a,r7
sel rb1
retr

start_game:
call gfxoff

; initialize sprite @(32,32), white
mov r0,#vdc_spr0_ctrl
mov a,#32
movx @r0,a
inc r0
mov a,#32
movx @r0,a
inc r0
mov a,#col_spr_white
movx @r0,a

; set shape
mov r0,#vdc_spr0_shape
mov r1,#8
mov a,#255
init_sprite0_loop:
movx @r0,a
inc r0
djnz r1,init_sprite0_loop

main_loop:
; wait for beginning of frame...
call waitvsync
call gfxoff ; disable VDC access

; set sprite y-pos to 32
mov r0,#vdc_spr0_ctrl
mov a,#32
movx @r0,a

; and move it across the screen so we know we haven't crashed yet :-)
inc r0
movx a,@r0
inc a
movx @r0,a

; starting color
mov r0,#vdc_color
mov a,#col_bck_blue
movx @r0,a

; start timer
mov a,#255-100  ;64 not enough
mov t,a
start t
en tcnti

; turn graphics on
call gfxon

jmp main_loop

; force to 2048 rom size
org $bff
db 0

end
Logged
Mux
Trying to get the cartridge in...
*
Posts: 40



« Reply #5 on: May 02, 2019, 07:31:38 AM »

Awesomeness!

Thanks so much for clearing that up, Ted!!!! The grid can actually stay on as we're not updating that, which is cool (see section 4.6 in Dan Boris' O2doc). I guess I skipped over bit #5 where it states you can't change anything when it's set. Ditto for the grid.

The unfortunate part is that this applies to all foreground objects. I'll have to fiddle around a bit with the code to see what I can get away with and will keep everyone posted!

I'm out for work the next few days but will see if I can get some stuff done :-) Will share any findings here!

Thanks again so much!!!!

-Mux
Logged
TedFoolery
Played Munchkin once...
**
Posts: 75


« Reply #6 on: May 02, 2019, 04:52:50 PM »

Yes - if you look at Puzzle Piece Panic, you'll see I had the same issue. I reused the sprites multiple times to get the Tetris play area, but there are no other characters displayed to the right of the the play area because I had to turn off the gfx to update the sprites - basically on each line.
I was able to keep the grid on and used the grid lines to display the level number - at least something was there so it wasn't dead space.
Logged
Mux
Trying to get the cartridge in...
*
Posts: 40



« Reply #7 on: May 02, 2019, 05:15:40 PM »

I'll see what I can come up with Smiley

One of the things I love about limited platforms is that it pushes your creativity and imagination a lot to come up with solutions. Reminds me of doing demos in the old days :-)

Either way, I'll keep you posted!
Logged
Mux
Trying to get the cartridge in...
*
Posts: 40



« Reply #8 on: May 03, 2019, 12:57:56 AM »

Follow-up question (from a meeting room during work, ahem. cough cough)

I messed around with it yesterday and the emulator didn't seem to disable rendering when you enable CPU access. Does anyone know whether or not enabling CPU access in the vdc_control registers disables rendering?

I'll try to confirm it later but figured I'd ask...

-Mux
Logged
LD
Pedit5
Attacked the Timelord
*
Posts: 136



« Reply #9 on: May 04, 2019, 12:45:42 AM »

I think O2em display chars even if it was disabled on register 0A0h.
You should always test your code on real hardware, if possible.
Logged
Mux
Trying to get the cartridge in...
*
Posts: 40



« Reply #10 on: May 04, 2019, 05:19:53 AM »

Yup, I know.. Need to get an o2 first! :-)
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!