Page 1 of 1

Re: Help with attributes and logical and (z80 assembler)

Posted: Sat Jul 04, 2020 6:51 pm
by MatGubbins
PeterJ wrote: Sat Jul 04, 2020 6:16 pm
MatGubbins wrote: Sat Jul 04, 2020 6:09 pm Placing quotes around the letters make it easier for you to read. There was also a stray 22,1,0,32 ; at 1,0,"space" at the start.

Great start into the world of machine code Peter!
Thanks @MatGubbins. It's only taken me 35 years and 100s of false starts!

Good idea about improving readability. The printing of a space is to clear the B from Bytes which appears after loading the code.
Ah! I see, so you need the CLS rom routine...or be clever and write a faster one! Hang on, the code is there in your program, just need to change a few numbers and you're there.

Re: Help with attributes and logical and (z80 assembler)

Posted: Sat Jul 04, 2020 7:21 pm
by PeterJ
Thank you for pointing me in the right direction [mention]MatGubbins[/mention], but not giving me the answer. That is a great way to learn. I was clearing the attribute memory, rather than the pixel memory!

Code: Select all

clsscr              
    xor a
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),a
    ldir
    ret

Re: Help with attributes and logical and (z80 assembler)

Posted: Sat Jul 04, 2020 7:30 pm
by PeterJ
Many thanks to you all for the suggestions. My finished code (for this evening) is:

Code: Select all

org $6000

main
    call clsscr
    call border
    call text
    ld hl,22528         ;start of attribute memory
    ld de,32            ;used to jump up and down rows on left and right
    ld b,31             ;counter for columns

top                     ;fill the top row
    push hl
    call random
    and 56
    pop hl
    ld (hl),a
    inc hl
    djnz top
    ld b,23

right                   ;fill the right hand side
    push hl
    call random
    and 56
    pop hl
    ld (hl),a
    add hl,de
    djnz right
    ld b,31

bottom                  ;fill the bottom
    push hl
    call random
    and 56
    pop hl
    ld (hl),a
    dec hl
    djnz bottom
    ld b,23

left                   ;fill the left
    push hl
    call random
    and 56
    pop hl
    ld (hl),a
    sbc hl,de
    djnz left

waitkey                 ;From JC Book - Thanks!
    ld hl,23560
    ld (hl),0
wait
    ld a,(hl)
    cp 0
    jr z,wait
    ret

random                  ;From JC Book - Thanks!
    ld hl,(seed)        ;Pointer        
    ld a,h
    and 31              ;keep it within first 8k of ROM.
    ld h,a        
    ld a,(hl)           ;Get "random" number from location.
    inc hl              ;Increment pointer.
    ld (seed),hl
    ret 
seed defw 0

clsscr                  ;Thanks to seven-fff
    xor a
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),a
    ldir
    ret

text                    ;Thanks to seven-fff for the idea
    ld a,2              ;upper screen        
    call 5633           ;open channel        
    ld de,string        ;address of string        
    ld bc,eostr-string  ;length of string to print        
    call 8252           ;print our string        
    ret
string defb 22,7,7,17,0,19,1,16,2,"S",16,6,"P",16,5,"E",16,3,"C",16,7,"T",16,4,"R",16,2,"U",16,6,"M",16,0," "
       defb 16,5,"C",16,3,"O",16,7,"M",16,4,"P",16,2,"U",16,6,"T",16,5,"I",16,3,"N",16,7,"G"
eostr  equ $ 

border
    ld a,0
    out ($FE),a
    ret

END $6000

Re: Help with attributes and logical and (z80 assembler)

Posted: Sat Jul 04, 2020 7:48 pm
by utz
PeterJ wrote: Sat Jul 04, 2020 6:14 pm Thank you @utz. I will need to look at that one written down in binary so I understand!
Hehe, I was thinking whether I should give an explanation, but I figured you could work it out on your own. And ideed you immediately had the right idea: Looking at the number in binary will give you the answer as to why this works.

That's one reason why I prefer using hexadecimal numbers: They're easier to translate into binary. And now for some practise:
https://flippybitandtheattackofthehexad ... ase16.com/

Best of luck with your assembly adventures!

Re: Help with attributes and logical and (z80 assembler)

Posted: Sat Jul 04, 2020 8:26 pm
by MatGubbins
Brilliant. You feel like a king for the day!

Re: Help with attributes and logical and (z80 assembler)

Posted: Sat Jul 04, 2020 9:09 pm
by Ast A. Moore
utz wrote: Sat Jul 04, 2020 7:48 pm And now for some practise:
https://flippybitandtheattackofthehexad ... ase16.com/
Goodness me! After five minutes of utter frustration I realized you could flip the bits by hitting the number keys! (Yeah, I didn’t scroll down for the instructions.) :lol:

Re: Help with attributes and logical and (z80 assembler)

Posted: Sat Jul 04, 2020 10:48 pm
by azesmbog
PeterJ wrote: Sat Jul 04, 2020 5:22 pm Hi,
I wrote a little routine to put random attributes around the border of the screen.
He also wrote a program with colored squares along the border of the screen. only for some reason they were outside the border :)
https://youtu.be/mfzlofEvy3U?t=22

Re: Help with attributes and logical and (z80 assembler)

Posted: Sun Jul 05, 2020 10:20 am
by Lethargeek
PeterJ wrote: Sat Jul 04, 2020 7:21 pm Thank you for pointing me in the right direction @MatGubbins, but not giving me the answer. That is a great way to learn. I was clearing the attribute memory, rather than the pixel memory!

Code: Select all

clsscr              
    xor a
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),a
    ldir
    ret

Code: Select all

clsscr              
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),l
    ldir
    ret

Re: Help with attributes and logical and (z80 assembler)

Posted: Sun Aug 02, 2020 11:17 am
by XoRRoX
Lethargeek wrote: Sun Jul 05, 2020 10:20 am

Code: Select all

clsscr              
    ld hl,16384
    ld de,16384 +1
    ld bc,6144-1
    ld (hl),l
    ldir
    ret
Smart. I realised that this will make more sense when numbers are used in hex.

Re: Help with attributes and logical and (z80 assembler)

Posted: Sun Aug 02, 2020 12:16 pm
by Guesser
utz wrote: Sat Jul 04, 2020 7:48 pm That's one reason why I prefer using hexadecimal numbers: They're easier to translate into binary. And now for some practise:
https://flippybitandtheattackofthehexad ... ase16.com/
That's jolly addictive. I got my high score up to 39 before the arm cramp stopped me playing more.