; The Mono Emulator. By Mick West.  September 1987.

; Routine to make the ST think it is in mono mode. Needs TOS in ROM
; Makes the system think that there is a mono screen, but actually
; be updating a medium real screen from this under Vblank interrupt
; The XBIOS calls; Physbase,Setscreen and Getrez are revectored.

START:
 MOVE.L #MESSAGE,-(SP)
 MOVE.W #9,-(SP)                ; Print startup message
 TRAP #1
 ADDQ.L #6,SP

INLOOP:
 MOVE.L #INPUT,-(SP)
 MOVE.W #9,-(SP)                ; Print input message
 TRAP #1
 ADDQ.L #6,SP
 MOVE.B #3,MESSAGE              ; InpuŸŸ€ŸˆàáŸ  0#Ÿ˜ 0<00ƒ€‡„àáŸ  0Ÿ˜Œƒ€‡„àáŸ	<Ÿ˜ŒŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ€Ÿ$Ÿ	àáŸ<33#Ÿ˜ƒàáŸ  0Ÿ˜ƒƒ3ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ€Ÿ3Ÿ€ŸƒàáŸ9Ÿ 0<00€ŒàáŸ90Ÿ301<#ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ€Ÿ$Ÿ€àáŸ8 9Ÿ˜Œƒ 0<00€ŒŸŸŸŸŸŸŸŸŸŸŸŸŸ€ŸŸŸŒŸŸàáŸ90Ÿ$!#  àáŸ8#	Ÿ3àáŸ  09Ÿ 0<00€‰ƒ3ŸŸŸŸŸŸŸŸŸŸŸŸ€Ÿ	ŸàáŸ9Ÿ˜ƒ‡ƒ3àáŸ9#0Ÿ$!#  ŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸŸ€ŸŸàáŸ8 Ÿ˜„ƒ3àáŸBGT INLOOP                     ; Too High (>100)
 MULU #10,D0
 CLR.W D1
 MOVE.B MESSAGE+3,D1            ; second digit
 SUB.W #48,D1
 BLT INLOOP                     ; Too low
 CMP.W #9,D1
 BGT INLOOP                     ; Too high
 ADD.W D1,D0
 CMP.W #80,D0
 BGT INLOOP                     ; Check less than 80
DEFAULT:
 MOVE.W D0,SCANPOKE+2


 CLR.L -(SP)
 MOVE.W #32,-(SP)
 TRAP #1                        ; ENTER SUPER MODE
 ADDQ.L #6,SP

 MOVE.W  #$2700,SR              ; Normal ROM reset routine starts here
 RESET
 CMP.L   #$FA52235F,$FA0000.L
 BNE     FC003C
 LEA     FC003C,A6
 JMP     $FA0004.L
FC003C:
 LEA     FC0044,A6
 JMP     $FC05D8
FC0044:
 BNE     FC0050Ï˜@œÏÏÉÇÇÇÁÄÁÀ‘ÁÉ˜˜ÃÇÇÆ@‘ðp˜œGÇÀGÀðpÏ„À‘ÏÏÏž@Až@ppÏœÀ‘ÏÏÏÌIÄFAÆ@BDÀÁÉÇÁÄÀÃž@BppÏœ˜OÏÏÏÏ˜œGÇÀAðpÏ˜@‘ÏÏÉÇÁÄžCž@BA™ÇðpÏ„ÀœÏÏÏÉÇÁÄžCž@BppÏœ˜OÏÏÏÏ˜œGÇÀ@…!*)ª’"…!'"#!˜š…&§«"—&" ˜…&" #!˜˜ ›…%&¨ ˜†…#!˜š…&" ##& ˜…&§«"—!’– ˜†…&§«"—!’!˜   ; A5 To base of variable space
 CLR.L D0
 MOVE.B $FF8201,D0              ; Video base high
 LSL.L #8,D0
 MOVE.B $FF8203,D0              ; Video base low
 LSL.L #8,D0
 MOVE.L D0,A3
 MOVE.L MONO(A5),A0
 MOVE.L MED(A5),A1
 CMP.L A1,A3                    ; Is MED still the real screen
 BEQ MEDOK                      ; Yes so jump
 MOVE.L A3,A0
 MOVE.L A0,MONO(A5)             ; Set MONO From new Physbase
 MOVE.L A1,D0
 LSR.L #8,D0
 MOVE.B D0,$FF8203              ; Set Physbase back to MED
 LSR.L #8,D0
 MOVE.B D0,$FF8201
MEDOK:
 MOVE.L MONOPOS(A5),D2
 ADD.L D2,A0
 ADD.L D2,A1
 MOVE.W #10,D1
 TST.B $43E
 BNE COPYMOVE                   ; Set speed to 10 if using disk drive
 TST.B $9BE
 BNE COPYMOVE                     
 MOVE.W MONOLINES(A5),D1        ; Otherwise get preset speed
COPYMOVE:
 BSR XEND                       ; COMBINE & MOVE TWO MONO LINES
 SUBQ.L #2,A1                   ; BACK TO NORMAL PLANE
 ADD.L #160,MONOPOS(A5)         ; DOWN ONE MED, TWO MONO LINES
 ADD.W #1,MONOCOUNT(A5)         ; ONE MORE LINE
 CMP.W #200,MONOCOUNT(A5)       ; DONE 200 ?
 BNE NOT200
 MOVE.L #0,MONOPOS(A5)          ; BACK TO TOP OF SCREEN
 SUB.L #32000,A0                ; FOR MONO
 SUB.L #32000,A1                ; AND MED
 MOVE.W #0,MONOCOUNT(A5)        ; RESET THE COUNTER
NOT200:
 DBF D1,COPYMOVE                ; LOOP ROUND MONOLINES TIMES
 MOVEM.L (SP)+,D0-D7/A0-A6
 ADDQ.L #1,$466                 ; FIRST BIT OF NORMAL VBLANK
 SUBQ.W #1,$452                 ; TEST IF ENABLED
 BMI NOVBL                      ; SKIP IF NOT
 MOVEM.L D0-D7/A0-A6,-(A7)
 ADDQ.L #1,$462
 SUB.L A5,A5
 JMP $FC069E                    ; SKIP MONITOR DETECTION
NOVBL:
 ADDQ.W #1,$452
 RTE                            ; NO VBLANK SO RETURN

GEN:                            
 MOVE.W (A0)+,(A1)              ; FORTY MOVES TO MOVE ONE LINE
 ADDQ.L #4,A1

 SUB.L #158,A1                  ; A1 BACK TO THE START OF THE LINE
                                
 MOVE.W (A0)+,(A1)              ; THEN FORTY MOVES TO NEXT PLANE
 ADDQ.L #4,A1
 RTS

SPACE: DS.L 6
XEND:

MESSAGE:
 DC.B 27,'E','The Mono Emulator - Mick West 1987',13,10
 DC.B        'This program is Shareware, If you',13,10
 DC.B        'find it useful then send a donation to',13,10,13,10
 DC.B        'Mick West',13,10
 DC.B        '27 Lynton Drive',13,10
 DC.B        'Shipley',13,10
 DC.B        'West Yorkshire',13,10
 DC.B        'BD18 3DJ',13,10
 DC.B        'ENGLAND',13,10,13,10
 DC.B        'Your Donation will be used to ',13,10
 DC.B        'Develope more Shareware',13,10
 DC.B        'This program can be freely copied.',13,10
 DC.B 13,10,0
INPUT:
 DC.B 13,10
 DC.B        'Enter speed (10 to 80, return = 40) '
 
 EVEN
MONO:      EQU 0                ; ADDR OF MONO SCREEN
MED:       EQU 4                ; ADDR OF REAL MEDIUM SCREEN
MONOPOS:   EQU 8                ; POSITION IN MONO SCREEN
MONOLINES: EQU 12               ; NO OF LINES/VBLANK
MONOCOUNT: EQU 14               ; LINE NO IN MONO


