So $9004 is the vertical beam position. Isn't there a high bit for the position, or is there only 256 lines due to the Vic'2 resolution? I know PAL has more scan lines than NTSC but I don't know the differences off hand. Or is $9004 a count of 2 scan lines ie. 1 byte = 512 lines?
If I understand correctly, your code waits for line 17 and then 19. Is that to make sure that we're at the top of the display? Do you check 19 to make sure that it isn't wrapping around at near the bottom of the display for example?
Then I see there's a delay at Init_06.. and this is called a few times with ever increasing line values in Y.
Did you happen to post an overview of what your code is doing? There's quite a lot to absorb here. I am interested in knowing what the bare minimum requirements are for a stable raster routine that can change the aux (or border) colour on a particular line and at a particular horizontal position - it would be useful to find a resource that explains how the timing is done.. I am also wondering how tight-loop timing would work within a "game loop" too. A raster routine would need priority to display the right colours at the right time.. so would a game loop do other things once the raster has reached the bottom of the screen.. or reached a line where we don't care about register hacking/changing anymore?