What actually makes this 'machine code' program tick?

discussion of beeb/electron applications, languages, utils and educational s/w
Commie_User
Posts: 915
Joined: Wed Jan 27, 2016 12:50 am

What actually makes this 'machine code' program tick?

Postby Commie_User » Thu Oct 26, 2017 9:16 pm

It does what it does but how is it doing it?

I've already typed it in.

1989:

april.jpg
april2.jpg
Attachments
Electron User.zip
(655 Bytes) Downloaded 7 times

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: What actually makes this 'machine code' program tick?

Postby jgharston » Thu Oct 26, 2017 10:49 pm

Does the disassembly through any light on it?

Code: Select all

0900 08          .    PHP
0901 48          H    PHA
0902 8A          .    TXA
0903 48          H    PHA
0904 98          .    TYA
0905 48          H    PHA
0906 CE 1F 09    N..  DEC &091F
0909 D0 0D       P.   BNE &0918
090B A2 00       ".   LDX #&00
090D BD 20 09    = .  LDA &0920,X
0910 F0 06       p.   BEQ &0918
0912 20 E3 FF     c.  JSR &FFE3
0915 E8          h    INX
0916 D0 F5       Pu   BNE &090D
0918 68          h    PLA
0919 A8          (    TAY
091A 68          h    PLA
091B AA          *    TAX
091C 68          h    PLA
091D 28          (    PLP
091E 60          `    RTS

091F 00          .    BRK
0920 16 06       ..   ASL &06,X
0922 0D 0D 41    ..A  ORA &410D
0925 70 72       pr   BVS &0999
0927 69 6C       il   ADC #&6C
0929 20 46 6F     Fo  JSR &6F46
092C 6F          o    EQUB &6F
092D 6C 21 0D    l!.  JMP (&0D21)
0930 00          .    BRK

It could be optimised a bit, the event routine doesn't need to save P, and Y isn't used so it doesn't need to save that either.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

crj
Posts: 313
Joined: Thu May 02, 2013 4:58 pm

Re: What actually makes this 'machine code' program tick?

Postby crj » Thu Oct 26, 2017 11:01 pm

It drops the code represented by the DATA statements into address &900 onwards, then redirects EVENTV to point at it.

Then it enables the vertical sync event (so it's called once for every frame of video, during flyback).

By my quick manual disassembly, the code is:

Code: Select all

.@0900 PHP : PHA : TXA : PHA : TYA : PHA
.@0906 DEC &091F : BNE &0918 : LDX #0
.@090D LDA &0920,X : BEQ &0918 : JSR OSASCI
.@0915 INX : BNE &090D
.@0918 PLA : TAY : PLA : TAX : PLA : PLP : RTS
.@091F EQUB 0
.@0920 EQUB 22,6 \ MODE 6
       EQUB 13, 13 \ CRLF, CRLF
       EQUS "April Fool!"
       EQUB 13 \ CRLF
       EQUB 0

So... every vertical flyback, it decrements the byte at &091F. If it's non-zero, it returns immediately. But if it's zero (which happens once every 5.12 seconds) it continues. It loops reading bytes from &0920 onwards. Each time round the loop, if the byte is zero it exits. Otherwise, it prints the byte, increments X and goes round again.

It's not exactly robust code, mind... (-8

Commie_User
Posts: 915
Joined: Wed Jan 27, 2016 12:50 am

Re: What actually makes this 'machine code' program tick?

Postby Commie_User » Fri Oct 27, 2017 12:13 am

I like the way they buried their punchline loop in a bunch of numbers, opening out for that classic zinger. Classic trap for the terminally unwary - in other words, me.

Thanks.


Return to “software: other”

Who is online

Users browsing this forum: No registered users and 8 guests