im looking for a way to turn the bright flag on and off in assembler

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

im looking for a way to turn the bright flag on and off in assembler

Post by 777 »

my program contains a loop that changes the ink and the paper colour in assembler.

here:

Code: Select all

ORG 40000
  CALL $daf
;ld a,$16
;rst 16
;ld a,0
;rst 16
;ld a,0
;rst 16
  LD A,33
ld b,8
ld c,0
ld d,0
LOOP:  
  CP 165
  RET Z
  PUSH AF
  RST 16
  ;ld a,8
;rst 16
ld a,$10
rst 16
ld a,b
add a,-1
rst 16
ld a,$11
rst 16
ld a,c
rst 16
inc c
;ld a,$13
;rst 16
;ld a,d
;rst 16
pop af
  INC A
djnz loop
ld b,8
ld c,0
;inc d
jr loop
how do i turn the bright flag on and off? the bright flag will only accept 1 or 0. is there an instruction that i can use that will go from 1 and back to 0 constantly? or even after 7 steps which is what is happening within the ink and paper routine of this program

* look at the bits of code that i have commented out at the bottom
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
Waldroid
Microbot
Posts: 118
Joined: Tue May 30, 2023 6:52 pm

Re: im looking for a way to turn the bright flag on and off in assembler

Post by Waldroid »

If you use an XOR $40 instruction to operate on each byte in the attributes it will toggle the BRIGHT bit each time it's run.
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: im looking for a way to turn the bright flag on and off in assembler

Post by 777 »

Waldroid wrote: Tue Jul 11, 2023 6:08 pm If you use an XOR $40 instruction to operate on each byte in the attributes it will toggle the BRIGHT bit each time it's run.
ok, i did try that but it only does 1 loop. where do i put it?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
Waldroid
Microbot
Posts: 118
Joined: Tue May 30, 2023 6:52 pm

Re: im looking for a way to turn the bright flag on and off in assembler

Post by Waldroid »

I'm looking through your code... Are you trying to print a line of exclamation marks in different colours?
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: im looking for a way to turn the bright flag on and off in assembler

Post by 777 »

Waldroid wrote: Tue Jul 11, 2023 7:45 pm I'm looking through your code... Are you trying to print a line of exclamation marks in different colours?
no. if you run it, it prints from ! to udg u across the screen in different inks and paper colours.
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
Waldroid
Microbot
Posts: 118
Joined: Tue May 30, 2023 6:52 pm

Re: im looking for a way to turn the bright flag on and off in assembler

Post by Waldroid »

Okay, I think this is what you're after. It makes every other character be bright.

Code: Select all

    ORG 40000

    CALL $daf                   ; Does a CLS.
    LD A,33                     ; Stores the current character, starting at '!'.
    ld b,8                      ; Stores ink colour.
    ld c,0                      ; Stores paper colour.
    ld d,0                      ; Not used.
    ld h,0                      ; Stores bright flag on/off (1/0).
LOOP:  
    CP 165                      ; Return when past the last UDG.
    RET Z
    
    PUSH AF
    RST 16

    ld a,$10                    ; Set ink colour...
    rst 16
    ld a,b
    add a,-1                    ; ... to iteration minus 1.
    rst 16
    
    ld a,$11                    ; Set paper colour.
    rst 16
    ld a,c
    rst 16
    inc c                       ; Increment colour for next character.

    ld a,$13                    ; Set bright flag.
    rst 16
    ld a,h
    xor 1                       ; Toggle flag for next character.
    ld h,a
    rst 16

    pop af

    INC A                       ; Move to the next character code.
    djnz LOOP
    
    ld b,8                      ; Reset ink and paper colours.
    ld c,0

    jr LOOP

User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: im looking for a way to turn the bright flag on and off in assembler

Post by 777 »

Waldroid wrote: Tue Jul 11, 2023 8:11 pm Okay, I think this is what you're after. It makes every other character be bright.

Code: Select all

    ORG 40000

    CALL $daf                   ; Does a CLS.
    LD A,33                     ; Stores the current character, starting at '!'.
    ld b,8                      ; Stores ink colour.
    ld c,0                      ; Stores paper colour.
    ld d,0                      ; Not used.
    ld h,0                      ; Stores bright flag on/off (1/0).
LOOP:  
    CP 165                      ; Return when past the last UDG.
    RET Z
    
    PUSH AF
    RST 16

    ld a,$10                    ; Set ink colour...
    rst 16
    ld a,b
    add a,-1                    ; ... to iteration minus 1.
    rst 16
    
    ld a,$11                    ; Set paper colour.
    rst 16
    ld a,c
    rst 16
    inc c                       ; Increment colour for next character.

    ld a,$13                    ; Set bright flag.
    rst 16
    ld a,h
    xor 1                       ; Toggle flag for next character.
    ld h,a
    rst 16

    pop af

    INC A                       ; Move to the next character code.
    djnz LOOP
    
    ld b,8                      ; Reset ink and paper colours.
    ld c,0

    jr LOOP

sorry, this doesnt seem to work. it just sets the bright flag to 1 across all the characters
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
Waldroid
Microbot
Posts: 118
Joined: Tue May 30, 2023 6:52 pm

Re: im looking for a way to turn the bright flag on and off in assembler

Post by Waldroid »

It works here. I assembled it using pasmo and tested it in fuse.
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: im looking for a way to turn the bright flag on and off in assembler

Post by 777 »

Waldroid wrote: Tue Jul 11, 2023 8:21 pm It works here. I assembled it using pasmo and tested it in fuse.
sorry, it is working, its just hard to see the way the bright is laid out
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
Waldroid
Microbot
Posts: 118
Joined: Tue May 30, 2023 6:52 pm

Re: im looking for a way to turn the bright flag on and off in assembler

Post by Waldroid »

No need to thank me or anything... :roll:
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: im looking for a way to turn the bright flag on and off in assembler

Post by 777 »

Waldroid wrote: Tue Jul 11, 2023 8:56 pm No need to thank me or anything... :roll:
sorry, thanks
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
Post Reply