{This is also in LABYRINTH, however maybe there people won't look at it} {That is why i am giving it its own space here and i have also added some extras} COMMODORE C128 in ACTION! - LOGICAL 'AND' EXPLAINED -------------------------------------------------------------------------------------------------- TOOL: Built-In ML-Monitor {Commodore C128} Language: Assembler Extra: None Author: Misel Zivanovic Note: (C) 17th DEC 2025 - www.lived.ch, mzretro.ch --------------------------------------------------------------------------------------------------- LOGICAL AND {e.g. lda #$bf, and #$03} . f0b17 29 03 and #$03 This is a tricky one! FIND EXPLAINATION BELOW! Let's check this code! If you run it with sys 2816 from BASIC it will deliver results in the right upper corner. we are running it with and #$03. It will deliver @,A,B,C {which are actually screen codes: 0,1,2,3} With and #$04 It will deliver @,A,B,C,D {which are actually screen codes: 0,1,2,3,4} This is the code from above, just the end part here was slightly modified: . 00b00 a9 00 lda #$00 . 00b02 8d 00 ff sta $ff00 . 00b05 a9 ff lda #$ff . 00b07 8d 0e d4 sta $d40e . 00b0a 8d 0f d4 sta $d40f . 00b0d a2 00 ldx #$00 . 00b0f a9 80 lda #$80 . 00b11 8d 12 d4 sta $d412 . 00b14 ad 1b d4 lda $d41b . 00b17 ea nop . 00b18 a9 bf lda #$bf POKE 2841,x {0-255} - This is instead of the random number . 00b1a 8d 27 04 sta $0427 Show it in the right upper corner . 00b1d 29 03 and #$03 Logical AND . 00b1f 8d 77 04 sta $0477 Show the result of it {depending on the number under POKE 2841,x} . 00b22 60 rts EXPLAINED: {I hope i did this understandable} --------------------------------------------------------------------------------------------------- As default we entered POKE 2841,191 {hex #$bf} BITS {0-7} & VALUES {1-128} = 255 when all is active binary that is: 1011 1111 {8 bit value} { 7 6 5 4 3 2 1 0} AND #$03 0000 0011 {128 64 32 16 8 4 2 1} ------------------------- 11 = 3 {0,1,2,3) {@,A,B,C} = C {wenn you run the code, it will be C} --------------------------------------------------------------------------------------------------- Here is why 191 is delivering C as a result! --------------------------------------------------------------------------------------------------- Practically, 191 is equal to 3, which is C as we know by now. binary for 3: 0000 0011 and we are watching just first 2 bits which also 191 is having active and that is counted together within the range we need 1+2 = 3 = C again. In other words, if we type POKE 2841,2 that would give us always a B {@=0, A=1, B=2, C=3} With POKE 2841,1 = A, and POKE 2841,0 = @ You can now easily guess what results will be delivered when we load random numbers {0-255} and just get values between 0 and 3! {NOTE: for 'and #$3' we need to watch just last two bits. You can ignore the rest} hex #$1c, dec 28, bin:0001 11 00 = @ {because our bits are 0, result is 0 = @} hex #$1d, dec 29, bin:0001 11 01 = A {because our bit is active: 1 = A} hex #$9f, dec 159, bin:1001 11 11 = C {because last 2 bits are active: 1+2 = C} Again, i really hope this was explained understandable! I added the code below which you can copy/paste and then experiment. --------------------------------------------------------------------------------------------------- CHECK IT FOR YOURSELF... {NORMAL VERSION} PART 1: BASIC Enter this first! 10 poke 2841,191 20 sys 2816 Then copy/paste this code below to ML-MONITOR and run the BASIC part. >00b00 a9 00 8d 00 ff a9 ff 8d:I.M..I.. >00b08 0e d4 8d 0f d4 a2 00 a9:.T..TB.I >00b10 80 8d 12 d4 ad 1b d4 ea:...TM.TJ >00b18 a9 bf 8d 27 04 29 03 8d:I..'.).. >00b20 77 04 60 00 00 00 00 00:W....... --------------------------------------------------------------------------------------------------- CHECK IT FOR YOURSELF... {EXTENDED VERSION, and #$0f, 0-15, however we will use just 1-15} FIRST COPY/PASTE THIS: { UPDATE, 17.12.2025: } { not really need but it won't mess anything if you use it } 10 scnclr 20 sys 2816:a=peek(2817) 30 char 1,0,5,str$(a) THEN COPY/PASTE THIS into ML-Monitor. Exit the Monitor with 'X' and type sys 2816 m b00 b62 >00b00 a2 0e a9 93 20 d2 ff a2:B.I. R.B >00b08 00 bd 52 0b 9d 00 04 e8:..r....H >00b10 e0 10 d0 f5 a9 00 ad 00:..PUI.M. >00b18 ff a9 ff 8d 0e d4 8d 0f:.I...T.. >00b20 d4 a9 80 8d 12 d4 ad 1b:TI...TM. >00b28 d4 29 0f c9 01 90 f2 aa:T).I..RJ >00b30 8e 01 0b a2 00 a9 51 9d:...B.Iq. >00b38 28 04 e8 ec 01 0b d0 f5:(.HL..PU >00b40 a9 05 85 eb a9 00 85 ec:I..KI..L >00b48 20 f0 ff 60 00 00 00 00: P...... >00b50 00 00 31 32 33 34 35 36:..123456 >00b58 37 38 39 30 31 32 33 34:78901234 >00b60 35 20 00 00 00 00 00 00:5 ...... EXPLAINED! d b00 fff . 00b00 a2 0e ldx #$0e location to temporary save the random number {needed for the balls} . 00b02 a9 93 lda #$93 = CHR$(147), clears the screen . 00b04 20 d2 ff jsr $ffd2 = BSOUT routine . 00b07 a2 00 ldx #$00 reset counter . 00b09 bd 52 0b lda $0b52,x get the numbers . 00b0c 9d 00 04 sta $0400,x show them here . 00b0f e8 inx increment counter for the next characters . 00b10 e0 10 cpx #$10 Is it dec 16 already . 00b12 d0 f5 bne $0b09 Repeat if not . 00b14 a9 00 lda #$00 Set BANK 15 . 00b16 ad 00 ff lda $ff00 Write to MMU 1 register . 00b19 a9 ff lda #$ff Charge accumulator with 255 . 00b1b 8d 0e d4 sta $d40e Write to low . 00b1e 8d 0f d4 sta $d40f and high byte of the frequency register . 00b21 a9 80 lda #$80 Write value of dec 128 . 00b23 8d 12 d4 sta $d412 into control register . 00b26 ad 1b d4 lda $d41b and are loading the value from the oscillator to accumulator {RANDOM NUMBER} . 00b29 29 0f and #$0f limit the choice to 4 bits which is resulting in numbers 0 - 15 . 00b2b c9 01 cmp #$01 we will ignore 0 . 00b2d 90 f2 bcc $0b21 remember? If the accumulator value is lower than COMPARE value then branch to where you want. In our case back to get a new random number. . 00b2f aa tax transfer that number to use it in FOR TO NEXT LOOP . 00b30 8e 01 0b stx $0b01 write it temporary to $0b01. We will need it later! . 00b33 a2 00 ldx #$00 reset counter . 00b35 a9 51 lda #$51 THE BALL {Or is it a BALL... Hmmm} . 00b37 9d 28 04 sta $0428,x Show it from here + x . 00b3a e8 inx Increment x . 00b3b ec 01 0b cpx $0b01 Compare it with the Random Number we saved previously @ $0b01 . 00b3e d0 f5 bne $0b35 LOOP . 00b40 a9 05 lda #$05 Reposition the cursor so it won't disturb our preview . 00b42 85 eb sta $eb set row . 00b44 a9 00 lda #$00 column value . 00b46 85 ec sta $ec set column . 00b48 20 f0 ff jsr $fff0 KERNAL routine to set {or read} the new cursor position according to your values . 00b4b 60 rts Who don't know what that is!!!