Videopac / Odyssey2 forum
November 12, 2019, 06:29:59 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Al lot of attachments from Nov 2011 till april 2012 are damaged. Please ask the original poster to re-upload if you need them.
 
   Home   arcade Help Login Register links videopac.nl  
Pages: [1]   Go Down
  Print  
Author Topic: Waiting for specific rasterline  (Read 1533 times)
Sdw
Trying to get the cartridge in...
*
Posts: 30


« on: August 07, 2017, 01:32:20 AM »

I am getting some really weird behavior when trying to wait for a specific raster line.
I'm using code based on what I found here:
http://videopac.nl/forum/index.php?topic=1756.15

So it looks like this:
Code:
; wait for scanline to arrive at next Y (r6) position
mov r0,#vdc_scanline ; pointer to VDC scanline register
mov r1,#vdc_scanrow ; pointer to VDC scanrow register
chky:
movx a,@r1 ; read scanrow
movx a,@r0 ; read scanline
add a,r6     ; add R6 (compare to -R6)
jnc chky

I am assuming that the line should feed it is the negative line number, so to wait for line 64, you feed it -64 = 0xc0, then when the raster counter reaches 64, the addition will overflow, the carry will be set and it will exit the loop.
The thing is, it doesn't seem to work as expected!
For one, what is the behavior of the scanline counter, since there are more than 256 lines, does it go 0-255, then 0-57 on a PAL system? And in that case, how do you make sure you are on the "right" count
I did a "call   waitvsync" first, in an attempt to be in a stable state, but still nothing works.
Even when feeding it values that should only be found once, like 128, it seems like the code doesn't work, but then if you add a couple of more waits a line 132 or something then it finally "zones" in correctly.

Can someone provide a very, very basic example, like:

wait vsync
set background to black
wait for line 32
set color to blue
wait for line 128
set color to white

That works?

It should be noted that I do all my testing in o2emwin, my flash cart didn't work at all, and I haven't heard back from the seller yet. Sad
Logged
Rene_G7400
Moderator
I take the Videopac and leave the Canoli!
*****
Posts: 2519



WWW
« Reply #1 on: August 07, 2017, 10:23:17 AM »

Usually the timer is used to change the background color. That way the processor doesn't have to wait and can continue to perform other tasks. When the timer reaches zero an interrupt is generated and a jump is done to some code that you have written to change the background color. Then you initialize the timer again for the next color change.
Setting the first color and initializing the timer is done after a waitvsync.
« Last Edit: August 07, 2017, 10:37:20 AM by Rene_G7400 » Logged
Sdw
Trying to get the cartridge in...
*
Posts: 30


« Reply #2 on: August 07, 2017, 11:18:01 AM »

Being able to use the timer would also be of interest for some cases, I have not found any documentation on how to use it though.

But also, I am very interested in getting the busy-wait-for-specific-rasterline code to work, as there are some effects I have in mind that will need that approach.
Logged
Sdw
Trying to get the cartridge in...
*
Posts: 30


« Reply #3 on: August 07, 2017, 11:48:22 AM »

Here's my code that tries to accomplish what I posted earlier, and it just results in a completely white screen!

Code:
; Necessary system BIOS calls

cpu 8048

include "g7000.a48"

; ============================================================================
Boot:
; ============================================================================
org 0400h ; Odyssey^2 ROM start
jmp selectgame ; system start or reset - select game
jmp irq           ; external IRQ - vblank routine  
jmp TimerInt           ; timer IRQ
jmp vsyncirq           ; vertical blank interrupt service
jmp StartGame ; Start of O2Test.bin
jmp soundirq ; Sound services

; ============================================================================
StartGame:
; ============================================================================
call init ; setup everything
call gfxoff ; stop display
call vdcenable


; ============================================================================
GameLoop: ;
; ============================================================================
call gfxon ; start display
call waitvsync ; wait for vbl

mov r0,#vdc_control
mov a,#002h
movx @r0,a

mov r0,#vdc_color
mov a,#col_bck_black
movx @r0,a

mov r6,#-32
; wait for scanline to arrive at next Y (r6) position
mov r0,#vdc_scanline ; pointer to VDC scanline register
mov r1,#vdc_scanrow ; pointer to VDC scanrow register
chky1:
movx a,@r1 ; read scanrow
movx a,@r0 ; read scanline
add a,r6           ; add R6 (compare to -R6)
jnc chky1

mov r0,#vdc_color
mov a,#col_bck_blue
movx @r0,a

mov r6,#-128
; wait for scanline to arrive at next Y (r6) position
mov r0,#vdc_scanline ; pointer to VDC scanline register
mov r1,#vdc_scanrow ; pointer to VDC scanrow register
chky2:
movx a,@r1 ; read scanrow
movx a,@r0 ; read scanline
add a,r6           ; add R6 (compare to -R6)
jnc chky2

mov r0,#vdc_color
mov a,#col_bck_white
movx @r0,a

jmp GameLoop ; rinse and repeat

; ============================================================================
TimerInt:
; ============================================================================
retr ; no timer needed as of yet
; ============================================================================

Can anyone spot any glaring errors?

-edit- fixed some copy-paste errors in the code
« Last Edit: August 07, 2017, 01:21:58 PM by Sdw » Logged
Rene_G7400
Moderator
I take the Videopac and leave the Canoli!
*****
Posts: 2519



WWW
« Reply #4 on: August 14, 2017, 09:40:22 AM »

Being able to use the timer would also be of interest for some cases, I have not found any documentation on how to use it though.

Have you read the following pages:
http://web.archive.org/web/20130608030041/http://soeren.informationstheater.de:80/g7000/toc.html

For example in chapter 9 the timer is used.
Logged
Rene_G7400
Moderator
I take the Videopac and leave the Canoli!
*****
Posts: 2519



WWW
« Reply #5 on: August 14, 2017, 09:45:01 AM »

VDC register A4 is reset to zero after VBlank ends, have you taken that into account? By checking the value of input T1 you can check when VBlank has ended.
Logged
Sdw
Trying to get the cartridge in...
*
Posts: 30


« Reply #6 on: August 15, 2017, 12:08:25 AM »

Excellent! Thank you, that seems to have solved it!

So now I do this:

   call   waitvsync      ; wait for vbl         
.wait:
   jt1   .wait   

And then I enter my busy-wait loop, and everything seems to behave as expected!
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!