home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !MAGS / !BONUS / COVERDSK / STFORMAT / STF48.ZIP / STF48.MSA / BORDERS / BORDER.S
Text File  |  1993-04-23  |  9KB  |  386 lines

  1. ;EXTRA_74.S by Alex Johnson
  2.  
  3. ;This code was written using devpac ST version 2
  4.  
  5.     opt    o+            ;optimisations on
  6.     opt    ow-            ;warnings off
  7.     opt    d+            ;debug on
  8.  
  9.     output    .tos            ;set tos output
  10.  
  11. start_up
  12.  
  13. ;gemdos start up
  14.  
  15.     move.l    4(sp),a0        
  16.     move.l    12(a0),d0        
  17.     add.l    20(a0),d0        
  18.     add.l    28(a0),d0        
  19.     add.l    #$1000,d0        
  20.     add.l    #$100,d0        
  21.     move.l    d0,-(sp)        
  22.     move.l    a0,-(sp)        
  23.     clr    -(sp)
  24.     move    #$4a,-(sp)        
  25.     trap    #1            
  26.     lea    12(sp),sp        
  27.  
  28.     move.l    #0,-(sp)        ;supervisor mode
  29.     move    #32,-(sp)
  30.     trap    #1
  31.     addq.l    #6,sp
  32.     move.l    d0,ustack        ;save user mode stack
  33.     lea    mstack,sp        ;set my stack to avoid misshaps
  34.  
  35. ;$ffff8240.w is the first colour palette register
  36.  
  37.     movem.l    $ffff8240.w,d0-d7    ;save old palette
  38.     movem.l    d0-d7,oldpal
  39.  
  40.     movem.l    blackout,d0-d7        ;black out screen
  41.     movem.l    d0-d7,$ffff8240.w
  42.  
  43. ;$fffffc02.w is the keyboard data register
  44.  
  45.     move.b    #$12,$fffffc02.w    ;mouse off
  46.     
  47. ;$484.w is the keyboard status
  48.  
  49.     move.b    $484.w,old484        ;save key stats
  50.     bclr     #0,$484            ;no keyclick
  51.     bclr     #1,$484            ;no repeat key
  52.  
  53. ;$ffff820a.w is the sync mode register (50hz or 60hz)
  54. ;$ffff8260.w is the resolution register
  55.  
  56.     move.b  $ffff820a.w,oldsync    ;save sync mode
  57.     move.b    $ffff8260.w,d0        ;get old res
  58.     and.l    #3,d0            ;mask off unwanted bits
  59.     move    d0,oldres        ;save old res
  60.  
  61.     bsr     vsync            ;wait for the vbl
  62.  
  63.     move.b  #2,$ffff820a.w        ;50HZ
  64.     clr.b   $ffff8260.w        ;Lowres
  65.  
  66.     move.w  #2,-(sp)        ;get physbase
  67.     trap    #14
  68.     addq.l  #2,sp
  69.     move.l  d0,physbase        ;save it
  70.  
  71.     move.w  #3,-(sp)        ;get logbase
  72.     trap    #14
  73.     addq.l  #2,sp
  74.     move.l  d0,logbase        ;save it
  75.  
  76. ;now we come to reserving some screen memory
  77. ;this source only needs one screen but by changing
  78. ;number in d0 you can reserve two or more screens
  79.  
  80. ;the normal screen is 32k but we are adding another
  81. ;74 lines to this screen so we need to make the area
  82. ;larger and this is how I work it out.
  83.  
  84. ;one screen line = 160 bytes
  85. ;normal screen = 200 lines
  86. ;divide this number by 1024 (one kilobyte)
  87. ;and then ALWAYS round it up to the nearest whole number.
  88. ;for a normal screen you would use:
  89.  
  90. ;200 * 160 = 32000
  91. ;32000/1024 = 31.25
  92. ;screen = 32k
  93.  
  94. ;but for this screen we use:
  95.  
  96. ;274 * 160 = 43840
  97. ;36640/1024 = 42.81
  98. ;screen = 43k
  99.  
  100.  
  101.     move.l  #(43*1024),d0        ;one 43k screen
  102.     bsr     reservemem        ;malloc the memory        
  103.     move.l  d0,screenmem        ;save memory address
  104.     and.l   #-256,d0        ;start on 256 byte boundary
  105.     add.l   #256,d0            ;just to make sure
  106.     move.l  d0,viewscreen        ;set screen address
  107.  
  108.  
  109.     move.l    viewscreen,d0        ;show the viewscreen
  110.     lsr.l    #8,d0
  111.     move.b    d0,$ffff8203.w        ;set vdbase low
  112.     lsr.w    #8,d0
  113.     move.b    d0,$ffff8201.w        ;set vdbase high
  114.  
  115.  
  116.     bsr    fillscreen
  117.  
  118.     move    #$2700,sr        ;switch off the interrupts
  119.     bsr    set_ints        ;put in our ones
  120.     move    #$2300,sr        ;switch them back on again
  121.  
  122.     move    #$777,$ffff8242.w    ;show the screen
  123.  
  124. ;now hopefully both borders should now be missing
  125.  
  126. .1
  127.     cmp.b    #$39,$fffffc02.w    ;space?
  128.     beq.s    reset
  129.     bra.s    .1
  130.  
  131. reset
  132.  
  133.     move    #$2700,sr        ;switch off the interrupts
  134.     bsr    restore_ints        ;put back the old ones
  135.     move    #$2300,sr        ;switch them back on again
  136.  
  137.     movem.l    blackout,d0-d7        ;black out colours
  138.     movem.l    d0-d7,$ffff8240.w
  139.  
  140.     move.b    oldsync,$ffff820a.w    ;restore old sync
  141.     move    oldres,-(sp)        ;restore old res
  142.     move.l    physbase,-(sp)        ;restore old physical screen
  143.     move.l    logbase,-(sp)        ;restore old logical screen
  144.     move    #5,-(sp)
  145.     trap    #14
  146.     lea    12(sp),sp
  147.  
  148.     move.b    #$8,$fffffc02.w        ;mouse on
  149.  
  150.     move.b    old484,$484.w        ;restore key stats
  151.  
  152.     move.l    screenmem,d0        ;free screen memory
  153.     bsr    freemem
  154.  
  155.     movem.l    oldpal,d0-d7        ;restore old pal
  156.     movem.l    d0-d7,$ffff8240.w
  157.  
  158.     move.l    ustack,-(sp)        ;user mode
  159.     move    #32,-(sp)
  160.     trap    #1
  161.     addq.l    #6,sp
  162.  
  163.     clr    -(sp)            ;terminate
  164.     move    #$4c,-(sp)
  165.     trap    #1
  166.  
  167.  
  168. vsync
  169.  
  170. ;sync with the electron beam
  171. ;to do this we check the fr clock register ($466.w)
  172. ;which is incremented every 50th second and wait
  173. ;for a different value
  174.  
  175.     move.l    d0,-(sp)
  176.     move.l    $466.w,d0        ;fr clock
  177. .1
  178.     cmp.l    $466.w,d0        ;check value
  179.     beq.s    .1            ;is it the same?
  180.     move.l    (sp)+,d0
  181.     rts
  182.  
  183. reservemem
  184.  
  185. ;use MALLOC to reserve some memory
  186. ;amount of memory needed is in d0
  187.  
  188.     
  189.     move.l    d0,-(sp)        ;area of memory
  190.     move    #$48,-(sp)        ;malloc
  191.     trap    #1
  192.     addq.l    #6,sp
  193.     rts
  194.  
  195. freemem
  196.  
  197. ;free the memory previously reserved with reserve mem
  198. ;address of memory is in d0
  199.  
  200.     move.l    d0,-(sp)        ;address of memory
  201.     move    #$49,-(sp)        ;free mem
  202.     trap    #1
  203.     addq.l    #6,sp
  204.     rts
  205.  
  206. fillscreen
  207.  
  208. ;this fills the screen with a line pattern
  209. ;one bitplane only
  210. ;274 lines
  211.  
  212.     movem.l    d0-d1/a0,-(sp)
  213.     move.l    viewscreen,a0        ;screen address
  214.     move    #(274-1),d0        ;screen lines to do
  215.     move    #$f0f0,d1        ;line bit pattern
  216. .1
  217.     move    d1,(a0)            ;fill the screen
  218.     move    d1,8(a0)        ;one bitplane only
  219.     move    d1,16(a0)
  220.     move    d1,24(a0)
  221.     move    d1,32(a0)
  222.     move    d1,40(a0)
  223.     move    d1,48(a0)
  224.     move    d1,56(a0)
  225.     move    d1,64(a0)
  226.     move    d1,72(a0)
  227.     move    d1,80(a0)
  228.     move    d1,88(a0)
  229.     move    d1,96(a0)
  230.     move    d1,104(a0)
  231.     move    d1,112(a0)
  232.     move    d1,120(a0)
  233.     move    d1,128(a0)
  234.     move    d1,136(a0)
  235.     move    d1,144(a0)
  236.     move    d1,152(a0)
  237.     lea    160(a0),a0        ;next screen line
  238.     dbra    d0,.1            ;do all screen lines
  239.     movem.l    (sp)+,d0-d1/a0
  240.     rts
  241.  
  242. set_ints
  243.  
  244. ;initialise timer b interrupt to
  245. ;remove the bottom border and
  246. ;switch off timer c to avoid any
  247. ;interference.
  248. ;it also initialises our vbl interrupt
  249.  
  250.     move.l    $70.w,oldvbl        ;save old vbl
  251.     move.l    $120.w,old120        ;save old timer b vector
  252.     move.b    $fffffa07.w,olda07    ;save old mfp registers
  253.     move.b    $fffffa09.w,olda09
  254.     move.b    $fffffa13.w,olda13
  255.     move.b    $fffffa15.w,olda15
  256.     move.b    $fffffa17.w,olda17
  257.     move.b    $fffffa1b.w,olda1b
  258.     move.b    $fffffa21.w,olda21
  259.     andi.b    #$df,$fffffa09.w    ;timer c off
  260.     andi.b    #$fe,$fffffa07.w    ;timer b off
  261.     ori.b    #1,$fffffa07.w        ;init timer b
  262.     ori.b    #1,$fffffa13.w
  263.     bclr    #3,$fffffa17.w        ;set automatic end of interrupt
  264.     bset    #6,$fffffa09.w
  265.     bset    #6,$fffffa15.w
  266.     move.l    #ourvbl,$70.w        ;set up our vbl
  267.     rts
  268.  
  269. restore_ints
  270.  
  271. ;restore all system interrupts
  272.  
  273.     move.l    oldvbl,$70.w        ;restore old vbl
  274.     move.l    old120,$120.w        ;restore old timer b vector
  275.     move.b    olda07,$fffffa07.w    ;restore old mfp registers
  276.     move.b    olda09,$fffffa09.w
  277.     move.b    olda13,$fffffa13.w
  278.     move.b    olda15,$fffffa15.w
  279.     move.b    olda17,$fffffa17.w
  280.     move.b    olda1b,$fffffa1b.w
  281.     move.b    olda21,$fffffa21.w
  282.     rts
  283.  
  284. ourvbl
  285.  
  286. ;first thing we do is remove the top border
  287.  
  288. ;we need to wait 17218 clock cycles before opening
  289. ;the top border. Don`t ask me why this is because i
  290. ;don't know
  291.  
  292. ;DO NOT CHANGE THE FOLLOWING PIECE OF CODE
  293.  
  294. ;if you do the hertz change will occur in the wrong
  295. ;place and the desired effect will not be achieved
  296.  
  297.     move.w    #$2700,sr        ;16
  298.     movem.l    d0-d7/a0-a6,regis    ;132
  299.     move    #(1421-1),d0        ;8
  300. .1
  301.     dbra    d0,.1            ;(1421*12)+10 = 17062
  302.  
  303. ;17218 cycles so open the top border
  304. ;don`t worry this is quite safe because the 60hz/50hz
  305. ;switch is done so fast that is isn`t noticed
  306.  
  307.     move.b    #0,$ffff820a.w        ;60hz
  308.     dcb.w    10,$4e71
  309.     move.b    #2,$ffff820a.w        ;back to 50hz
  310.  
  311. ;if all has gone well the top border has now been removed
  312.  
  313. ;now we have to set up timer b to remove
  314. ;the bottom border.
  315.  
  316.     clr.b    $fffffa1b.w        ;stop timer b
  317.     move.b    #228,$fffffa21.w    ;set it to occur on line 228
  318.     move.l    #ourtb,$120.w        ;set up our timer b vector
  319.     move.b    #8,$fffffa1b.w        ;start timer b
  320.     movem.l    regis,d0-d7/a0-a6    ;restore registers
  321.     move    #$2300,sr        ;interrupts back on
  322.     st    vblflag            ;signal we have finished
  323.     rte                ;finish
  324.  
  325. ourtb
  326.  
  327. ;this is the timer b interrupt that removes
  328. ;the bottom screen border
  329.  
  330.     clr.b    $fffffa1b.w        ;stop timer b
  331.     movem.l    a0/d0,-(sp)        ;save a0 and d0
  332.     lea    $fffffa21.w,a0        ;timer b data register
  333.     move.b    #229,(a0)        ;set it to occur on line 229
  334.     move.b    #8,$fffffa1b.w        ;start timer b
  335.     moveq    #0,d0            ;clear d0
  336.     move.b    (a0),d0            ;get timer b data
  337. .1
  338.     cmp.b    (a0),d0            ;compare timer b data
  339.     beq.s    .1            ;is it the same?
  340.  
  341. ;here is another 60hz/50hz switch don`t worry this
  342. ;one is also safe to use
  343.  
  344.     clr.b    $ffff820a.w        ;60hz
  345.     moveq    #3,d0            ;we need to
  346. .2
  347.     nop                ;wait a little while
  348.     dbra    d0,.2            ;for the switch to take effect
  349.     move.b    #2,$ffff820a.w        ;back to 50hz
  350.  
  351. ;the bottom border is now history
  352.  
  353.     movem.l    (sp)+,a0/d0        ;restore a0 and d0
  354.     clr.b    $fffffa1b.w        ;stop timer b
  355.     rte                ;finish
  356.  
  357.     section    bss
  358.  
  359. ustack        ds.l    1        ;user stack pointer
  360.         ds.l    512        ;my stack
  361. mstack        ds.l    1        ;stacks go backwards
  362. oldpal        ds.w    16        ;old palette
  363. blackout    ds.w    16        ;black out colours
  364. old484        ds.b    1        ;old key status
  365. oldsync        ds.b    1        ;old sync mode
  366. oldres        ds.w    1        ;old resolution
  367. logbase        ds.l    1        ;logical screen
  368. physbase    ds.l    1        ;physical screen
  369. screenmem    ds.l    1        ;screen memory address
  370. viewscreen    ds.l    1        ;new screen
  371.  
  372. oldvbl        ds.l    1        ;old vbl ($70.w)
  373. old120        ds.l    1        ;old timer b ($120.w)
  374.  
  375. olda07        ds.b    1        ;old mfp registers
  376. olda09        ds.b    1
  377. olda13        ds.b    1
  378. olda15        ds.b    1
  379. olda17        ds.b    1
  380. olda1b        ds.b    1
  381. olda21        ds.b    1
  382. vblflag        ds.b    1        ;vbl flag
  383.         even
  384.  
  385. regis        ds.l    16        ;store for the 16 registers
  386.