Oldschool Gaming - reviewing new games on classic computers
It is currently Wed Sep 08, 2010 5:31 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Na Na Na Na Naah!
PostPosted: Sun Jul 25, 2010 8:36 pm 
Offline

Joined: Sun Aug 12, 2007 8:25 pm
Posts: 262
Location: Somewhere in the virtual Ether...
Something for the Speccy:
Code:
; This routine will hopefully scroll the screen,
; let's put it at 32768 in RAM
        org $8000
        ld a,7          ; Colour seven is white ink on black paper
        ld (23693),a    ; Sets the colour as above
        call 3503       ; Calls the routine to clear screen
        ld a,0          ; Zero is black
        call 8859       ; Sets the border colour
INFINITE
        ld a,22         ; 22 is the Sinclair ROM value for PRINT AT
        rst $10         ; Call the ROM PRINT routine as above
        ld a,0          ; So, we need an x and y co-ord for PRINT AT
        rst $10         ; like in BASIC
        rst $10         ; so we call it twice (PRINT AT 0,0;)
        ld bc,STRING    ; Points the register bc to STRING
LOOP
        ld a,(bc)       ; Puts the current byte at bc into a
        cp 0            ; Compares a to zero
        jr z,MOVEBYTE   ; If equal to zero, jump to MOVEBYTE
        rst $10         ; Outputs a to the screen
        inc bc          ; Increases bc by one
        jr LOOP         ; Goes back to LOOP
MOVEBYTE
        ld bc,STRING    ; Let's point bc at the start of STRING again
        ld de,OFFSET    ; And de at OFFSET, which is one byte before
        ld a,(bc)       ; Get the first byte at bc and put into a
        ld (de),a       ; the byte at OFFSET
SCROLL
        inc bc          ; Increase bc by one
        inc de          ; Increase de by one
        ld a,(bc)       ; Get the current location of bc at store in a
        cp 0            ; Compare a to zero
        jr z,AGAIN      ; We'll jump to AGAIN if it equals zero
        ld (de),a       ; Store a at de (one byte before bc)
        jr SCROLL   ; Jumps to SCROLL and does it all again
AGAIN
        ld a,(OFFSET)   ; Puts the byte at OFFSET into a
        ld (de),a       ; Store a at location de (end of STRING before zero)
        ld b,%00000101  ; Now we're using the register b
DELAY
        halt            ; Stop everything and wait for an interupt
        djnz DELAY      ; Loop back until interupt is found
        jr INFINITE     ; Jump back to INFINITE
OFFSET
        defb %11111111  ; byte used in MOVEBYTE and AGAIN
STRING         ; Main text to scroll
        defb 32,32,32,32,32,32,"Na Na Na Na Naah!",32,32,32,32,32,32,32,32,32
        defb 0      ; End

Regards,

Shaun.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Na Na Na Na Naah!
PostPosted: Mon Aug 02, 2010 5:18 pm 
Offline
OSG Staffer

Joined: Fri Aug 17, 2007 3:54 pm
Posts: 19
Location: Watford
looking at your comments...

Code:
        ld b,%00000101  ; Now we're using the register b
DELAY
        halt            ; Stop everything and wait for an interupt
        djnz DELAY      ; Loop back until interupt is found


the 'djnz' instruction actually subtracts one from register B and jumps if the result isn't zero - so what it's actually doing is looping around the HALT instruction 5 times.

It doesn't actually have anything to do with waiting for the interrupt.


but still.. nice work :)

_________________
http://onabitplane.blogspot.com/ - Amiga/ST-based fiddling


Top
 Profile  
 
 Post subject: Re: Na Na Na Na Naah!
PostPosted: Tue Aug 03, 2010 10:02 pm 
Offline

Joined: Sun Aug 12, 2007 8:25 pm
Posts: 262
Location: Somewhere in the virtual Ether...
sack wrote:
looking at your comments...

Code:
        ld b,%00000101  ; Now we're using the register b
DELAY
        halt            ; Stop everything and wait for an interupt
        djnz DELAY      ; Loop back until interupt is found


the 'djnz' instruction actually subtracts one from register B and jumps if the result isn't zero - so what it's actually doing is looping around the HALT instruction 5 times.

It doesn't actually have anything to do with waiting for the interrupt.


but still.. nice work :)

Cheers Sack, I must have misunderstood the example. Actually, this has nothing to do with scrolling the screen, as the comment at the top suggests. What it's doing is moving the string of memory one byte at a time to it's position-1, getting the first byte of the string and then sticking it at the end so you have an infinite loop, so it looks as though there's screen manipulation when actually there isn't. It's just rewriting the string at each pass, and each time the byte is shifted it's thrown out the the top line of the screen again using Sinclair's rather handy ROM.

Regards,

Shaun.

_________________
Image


Top
 Profile  
 
 Post subject: Re: Na Na Na Na Naah!
PostPosted: Sat Aug 14, 2010 10:03 am 
Offline

Joined: Sun Aug 12, 2007 8:25 pm
Posts: 262
Location: Somewhere in the virtual Ether...
Here's another routine I found that does a simple colour roll:
Code:
SCR EQU 16384           ; Screen Ram
   ORG $8000
   LD BC,ROLL   ; Hopefully, this is going to work...
   PUSH BC      ; Got the first location of ROLL and put it into BC
   LD A,(BC)   ; Now load A with the first byte of ROLL
   LD (23693),A   ; set screen colours
   CALL 3503   ; clear the screen
   LD A,1      ; One is blue
   CALL 8859   ; Set border to blue
BEGIN
   LD BC,STRING   ; BC=STRING location in memory
   LD DE,SCR    ; DE=SCR or 16384
LOOP
   LD A,(BC)   ; A=Value of BC
   CP 0      ; Compare A to zero (end of STRING)
   JR Z,NEXTCOL   ; If equal then branch to NEXTCOL label
   RST $10      ; Output A to screen
   INC BC      ; Increace BC by 1 to get the next location of the STRING data
   INC DE      ; Increade DE by 1 to get the next cursor position
   JR LOOP    ; Branch back to LOOP label
NEXTCOL         ; This is where we loop back to do the colour roll
   POP BC      ; Okay, so we need to call BC back from the stack
   INC BC      ; Now this will increase it by one
   PUSH BC      ; Right, so we'll push it back to the stack so that we read the next byte next time around
   LD A,16      ; Loading A with 16 and then calling RST $10 will tell the Speccy that the next byte will
   RST $10      ; be the INK colour, which we'll call from the current location stored at BC
   LD A,(BC)   ; so now A is the next byte in the ROLL bit of memory
   CP 0      ; Right, let's compare it to zero and...
   JR Z,RESTART   ; ... if it is zero then we're at the end of the colour roll data
   RST $10      ; And if not, then we output the text colour to screen so that when the text is redrawn,
         ; it's a new colour, innit?
   LD A,22      ; Okay, so if A=22 and there's an RST $10 after it then that means we're going to tell the
         ; Speccy that we're relocating the curson
   RST $10      ; and therefore we want to relocate it at position
   LD A,0      ; zero twice, or 0,0 in the PRINT X,Y thingy
   RST $10      ; so A is now equal to zero, and as the X and Y locations need to be that to redraw over
   RST $10      ; the text, we just call RST $10 twice so the text is redrawn in the new colour
   JR BEGIN   ; Now, let's go back to the label BEGIN to redraw the text in the new colour
RESTART
   LD BC,ROLL   ; Oh no! Zero has been detected, so what are we going to do about it? Well, obviously we
   PUSH BC      ; don't want to keep reading bytes of memory after the ROLL data or we will hit an error eventually
   LD A,(BC)   ; as the INK colour will not be valid, so this makes BC equal to the start of the data segment in
   RST $10      ; memory, pushes it to the stack, makes A equal to the start again and throws out the colour
   LD A,22      ; at the start of the ROLL bit.
   RST $10      ; We need to remember to set the PRINT AT 0,0 thingy again, or it'll redraw after the first string
   LD A,0      ; which will eventually fill the screen and ask you if you want to Scroll? No, we don't want that.
   RST $10      ; PRINT AT 0,0 is effectively set in this code now
   RST $10      ;
   JR BEGIN   ; So, we'll go back to the beginning and start again. Infinite loops are good :-)
ROLL
   DEFB 7,7,6,6,5,5,4,4,3,3,2,2,1,1,2,2,3,3,4,4,5,5,6,6,0
STRING
   DEFB "Na Na Na Na Naah!"   ; Here is the data
   DEFB 0            ; 0 is the end of data


Here's how the colour attribute for each cell is worked out:

Attribute value=(128*FLASH)+(64*BRIGHT)+(8*PAPER)+INK (FLASH and BRIGHT are either 0 or 1)

PAPER and INK can have the following values:
0=Black
1=Blue
2=Red
3=Magenta
4=Green
5=Cyan
6=Yellow
7=White

As you can see, the colour values go from the darkest to the brightest. This is demonstrated in the bit of memory called ROLL in which we are stepping the colours. Of course, you could slow things down by cellotaping a delay in there somewhere appropiate (see the first piece of code). In fact, those adventurous enough might want to add a colour roll to the scrolly text or something.

This is a relitively early piece of Z80 code for me on the Speccy, so there's probably room for improvements but at least it works and that's the main point ;-)

Regards,

Shaun.

_________________
Image


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Content copyright © 2004-2010 Oldschool Gaming     Designed and hosted by Enisoc Design