home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / mandel / mandel.asm < prev    next >
Assembly Source File  |  1990-06-14  |  112KB  |  4,196 lines

  1. ;*******************************
  2. ; mandel : mandelbrot figure
  3. ;        for FM-TOWNS
  4. ;    (C)1990.3.20 by Fumi
  5. ; #1 1990.4.3   Ver0.1 for SOFT BANK
  6. ; #2 1990.4.10  Ver1.0 first edition
  7. ;*******************************
  8.     .386p
  9. TRUE    equ    1
  10. FALSE    equ    0
  11. ;
  12. EGBSIZ    equ    2000    ; EGB work area byte size
  13. VRAMW    equ    1024    ; VRAM byte width
  14. VRAMDW    equ    640    ; VRAM display width
  15. VRAMDH    equ    480    ; VRAM display hight
  16. ;
  17. BGBW    equ    10    ; background block width
  18. BGBH    equ    10    ; background block hight
  19. BGBSIZ    equ    BGBW*BGBH    ; background block size
  20. BGBCN    equ    64    ; background block column number
  21. BGBLN    equ    48    ; background block line number
  22. ;
  23. SCRX    equ    40    ; display screen x position
  24. SCRY    equ    60    ; display screen y position
  25. SCRW    equ    400    ; display screen width
  26. SCRH    equ    400    ; display screen hight
  27. SCRADR    equ    SCRY*VRAMW+SCRX    ; display screen VRAM address
  28. ;
  29. TITX    equ    SCRX+(SCRW-TITW)/2    ; title box x position
  30. TITY    equ    20    ; title box y position
  31. TITW    equ    260    ; title box width
  32. TITH    equ    25    ; title box hight
  33. TITADR    equ    TITY*VRAMW+TITX    ; title box VRAM address
  34. ;
  35. PARX    equ    470    ; parameter box display x positon
  36. PARY    equ    60    ; parameter box display y position
  37. PARW    equ    140    ; paremeter box display width
  38. PARH    equ    75    ; parameter box display hight
  39. PARADR    equ    PARY*VRAMW+PARX    ; parameter box VRAM address
  40. ;
  41. PTX    equ    470    ; pallet table x position
  42. PTY    equ    145    ; pallet table y position
  43. PTW    equ    PTBCN*PTBW+40    ; pallet table boxwidth
  44. PTH    equ    PTBLN*PTBH+20    ; pallet table box hight
  45. PTADR    equ    PTY*VRAMW+PTX    ; pallet table start VRAM address
  46. PTBW    equ    4    ; pallet table block width
  47. PTBH    equ    10    ; pallet table block hight
  48. PTBCN    equ    25    ; pallet table block column number
  49. PTBLN    equ    10    ; pallet table block line number
  50. PTBADR    equ    (PTY+17)*VRAMW+(PTX+35)    ; pallet table block address
  51. ;
  52. MENUX    equ    470    ; menu display x position
  53. MENUY    equ    275    ; menu display y position
  54. MENUW    equ    140    ; menu display width
  55. MENUH    equ    185    ; menu display hight
  56. MENUADR    equ    MENUY*VRAMW+MENUX    ; menu start VRAM address
  57. ;
  58. LPOSX    equ    PARX+PARW-10*8-3+(PARY+18)*VRAMW    ; position x
  59. LPOSY    equ    PARX+PARW-10*8-3+(PARY+36)*VRAMW    ; position y
  60. LRESO    equ    PARX+PARW-10*8-3+(PARY+54)*VRAMW    ; resolution
  61. LLIMIT    equ    PARX+PARW-5*8-12+(PARY+72)*VRAMW    ; limit parameter
  62. LDSTEP    equ    MENUX+(MENUW-9*8)/2+(MENUY+110)*VRAMW    ; drawing step
  63. LZPOSX    equ    MENUX+MENUW-10*8-10+(MENUY+48)*VRAMW    ; zoom in position x
  64. LZPOSY    equ    MENUX+MENUW-10*8-10+(MENUY+66)*VRAMW    ; zoom in position y
  65. LCL1    equ    MENUX+70+(MENUY+46)*VRAMW    ; old limit
  66. LCL2    equ    MENUX+70+(MENUY+66)*VRAMW    ; new limit
  67. LAUP    equ    MENUX+(MENUW-5*8)/2+(MENUY+110)*VRAMW    ; auto up limit
  68. LCSTEP1    equ    MENUX+72+(MENUY+46)*VRAMW    ; color step change unit
  69. LCSTEP2    equ    MENUX+72+(MENUY+66)*VRAMW    ; color step
  70. ;
  71. EXTALL    equ    "LDM."    ; extension all
  72. EXTCOL    equ    "CDM."    ; extension col
  73. ;
  74. USRCN    equ    250    ; numbers of color
  75. PALSBS    equ    42    ; pallet set block size (not factor 1+USRCN)
  76. PALSBN    equ    (1+USRCN)/PALSBS+1    ; number of pallet block
  77. PALSBR    equ    (1+USRCN) mod PALSBS    ; number of rest pallet (inhibit 0)
  78. ;
  79. PADREP    equ    10    ; pad repeat count (unit VSYNC)
  80. INIREP    equ    -1    ; initial repeat counter code
  81. ;
  82. P$FWD    equ    1    ; TOWNS pad button
  83. P$BACK    equ    2
  84. P$LEFT    equ    3
  85. P$RIGHT    equ    4
  86. P$RUN    equ    5
  87. P$SEL    equ    6
  88. P$TRIG1    equ    01b
  89. P$TRIG2    equ    10b
  90. ;
  91. C$NULL    equ    0    ; system pallet code
  92. C$BLOCK    equ    251
  93. C$LIGHT    equ    252
  94. C$DARK    equ    253
  95. C$PANEL    equ    254
  96. C$INT    equ    255
  97. ;
  98. DS$NONE    equ    0    ; no first figure
  99. DS$ON    equ    1    ; on the way
  100. DS$FULL    equ    2    ; full display
  101. ;
  102. MINFR    equ    16    ; zoom up frame minimum size
  103. IPOSX    equ    -2 shl 24    ; initial position x
  104. IPOSY    equ    -2 shl 24    ; initial position y
  105. IRESO    equ    (4 shl 24)/SCRW    ; initial resolution
  106. ILIMIT    equ    250        ; initial limit
  107. ;
  108. boxstr    struc        ; down box structure
  109. boxadr    dd    ?    ; box start VRAM address
  110. boxw    dw    ?    ; box pixcel width
  111. boxh    dw    ?    ; box pixcel hight
  112. boxstr    ends
  113. menuitm    struc        ; menu items index structre
  114. butptr    dw    ?    ; buttons  pointer
  115. butnum    dw    ?    ; number of button
  116. strptr    dw    ?    ; strings pointer
  117. menuitm    ends
  118. butstr    struc        ; button data structure
  119. butadr    dd    ?    ; button start VRAM address
  120. butw    dw    ?    ; button pixcel width
  121. buth    dw    ?    ; button pixcel hight
  122. butstr    ends
  123. locdat    struc        ; location data structure
  124. locdatx    dd    ?    ; position x
  125. locdaty    dd    ?    ; position y
  126. locdatr    dd    ?    ; resolution
  127. locdatl    dw    ?    ; limit
  128. locdat    ends
  129.  
  130. data    segment    use32 rw
  131. ;*******************************
  132. ; variables
  133. ;*******************************
  134. buffer    dd    ?    ; calculate data buffer pointer
  135. bufsiz    dd    ?    ; buffer byte size (400*400*8 bytes)
  136. ;
  137. posx    dd    IPOSX    ; display position x
  138. posy    dd    IPOSY    ; display position y
  139. reso    dd    IRESO    ; resolution
  140. limit    dw    ILIMIT    ; upper limit of repeat number
  141. curstat    dw    DS$FULL    ; current display state
  142. step    dw    4    ; display step for dsp3q
  143. islin    dw    0    ; initial screen calculated line
  144. ;
  145. cura    dd    ?    ; current real part
  146. curb    dd    ?    ; current imaginary part
  147. pstep    dd    ?    ; position step (reso*step) for dsp3q
  148. bstep    dd    ?    ; block line VRAM step for ds3q
  149. hbnum    dw    ?    ; horizon block number for ds3q
  150. count1    dw    ?    ; public counter 1
  151. count2    dw    ?    ; public counter 2
  152. ;
  153. repcnt    dw    ?    ; pad repaet counter
  154. frame    dw    SCRX+SCRW*3/8,SCRY+SCRH*3/8,SCRW/4,SCRH/4    ; zoom up frame
  155. ;
  156. numwid    db    5    ; dispaly width of integer for putdec
  157. palpkt    label    byte    ; pallet data packet address
  158. palnum    db    1    ; pallet number
  159. bpal    db    0    ; blue pallet data
  160. rpal    db    0    ; red pallet data
  161. gpal    db    255    ; green pallet data
  162.     db    ?    ; dummy
  163. colnum    db    1    ; color number
  164. spflg    db    FALSE    ; saving pallet plag
  165. currgb    db    0    ; current B|R|G (B=0,R=1,G=2)
  166. exts    dd    ?    ; extension for open
  167. ;*******************************
  168. ; constants
  169. ;*******************************
  170. syspal    db    251,0,192,62    ; block
  171.     db    252,200,200,200    ; light shadow
  172.     db    253,10,10,10    ; dark shadow
  173.     db    254,120,120,120    ; panel
  174.     db    255,10,10,200    ; string
  175. syspalN    equ    5
  176. ;
  177. bgblock    db    0FCh,0FCh,0FCh,0FCh,0FCh,0FCh,0FCh,0FCh,0FCh,0FDh
  178.     db    0FCh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FDh
  179.     db    0FCh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FDh
  180.     db    0FCh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FBh,0FDh
  181.     db    0FDh,0FDh,0FDh,0FDh,0FDh,0FDh,0FDh,0FDh,0FDh,0FDh
  182.     db    0FCh,0FCh,0FCh,0FCh,0FDh,0FCh,0FCh,0FCh,0FCh,0FCh
  183.     db    0FBh,0FBh,0FBh,0FBh,0FDh,0FCh,0FBh,0FBh,0FBh,0FBh
  184.     db    0FBh,0FBh,0FBh,0FBh,0FDh,0FCh,0FBh,0FBh,0FBh,0FBh
  185.     db    0FBh,0FBh,0FBh,0FBh,0FDh,0FCh,0FBh,0FBh,0FBh,0FBh
  186.     db    0FDh,0FDh,0FDh,0FDh,0FDh,0FDh,0FDh,0FDh,0FDh,0FDh
  187. ;
  188. cmdtbl1    dd    zoomin,zoomout,whole,chgcol,chglim    ; menu1 dispatch
  189.     dd    load,save,main10,main99
  190. cmdtbl2    dd    indcol,setcs,grad,cload,csave,crest    ; change color dispatch
  191. ;
  192. mdrawon    menuitm    <butd,butdN,str3>    ; on drawing message items
  193. mzoin    menuitm    <but1,but1N,str6>    ; zoom in menu
  194. mcgl    menuitm    <but2,but2N,str7>    ; change limit menu
  195. mautad    menuitm    <butA,butAN,str8>    ; automatically limit addition menu
  196. mautup    menuitm    <butU,butUN,strU>    ; automatically limit up menu
  197. mcgc    menuitm    <but3,but3N,str9>    ; change color menu
  198. mindc    menuitm    <but4,but4N,strA>    ; change individual color menu
  199. mced    menuitm    <but5,but5N,strB>    ; color edit menu
  200. mexp    menuitm    <but6,but6N,strC>    ; extract pallet number from pixcel
  201. msave    menuitm    <but7,but7N,strD>    ; save menu
  202. mload    menuitm    <but8,but8N,strE>    ; load menu
  203. msetcs    menuitm    <but9,but9N,strF>    ; set color step menu
  204. mgrad    menuitm    <butG,butGN,strG>    ; gradation menu
  205. ;
  206. titbox    boxstr    <TITADR,TITW,TITH>    ; title box data
  207. scrbox    boxstr    <SCRADR,SCRW,SCRH>    ; screen box data
  208. parbox    boxstr    <PARADR,PARW,PARH>    ; parameter box data
  209. palbox    boxstr    <PTADR,PTW,PTH>        ; pallet box data
  210. menubox    boxstr    <MENUADR,MENUW,MENUH>    ; menu box data
  211. ;
  212. str1    dw    1,str11                ; title string index
  213. str2    dw    9,str21,str22,str23,str24    ; starting message
  214.     dw    str25,str26,str27,str28,str29
  215. str3    dw    3,str31,str32,str33        ; on drawing message index
  216. str4    dw    11,str411,str412,str413,str414    ; parameter box and
  217.     dw    str421,str422            ; pallet table scale strings
  218.     dw    str431,str432,str433,str434,str435
  219. str5    dw    6,str51,str52,str53,str54    ; scroll mode message
  220.     dw    str55,str56
  221. str6    dw    7,str61,str62,str63,str64    ; zoom in mode messag
  222.     dw    str65,str66,str67
  223. str7    dw    8,str71,str72,str73,str74    ; limit change
  224.     dw    str75,str76,str77,str78
  225. str8    dw    4,str81,str82,str83,str84    ; automatically limit addition
  226. strU    dw    4,strU1,strU2,strU3,strU4    ; automatically limit up
  227. str9    dw    2,str91,str92        ; change color menu
  228. strA    dw    10,strA1,strA2,strA3    ; change individual color menu
  229.     dw    strA4,strA5,strA6,strA7
  230.     dw    strA8,strA9,strA10
  231. strB    dw    7,strB1,strB2,strB3    ; edit color code
  232.     dw    strB4,strB5,strB6,strB7
  233. strC    dw    6,strC1,strC2,strC3    ; extract pallet number from pixcel
  234.     dw    strC4,strC5,strC6
  235. strD    dw    4,strD1,strD2,strD3,strD4    ; save
  236. strE    dw    5,strE1,strE2,strE3,strE4,strE5    ; load
  237. strF    dw    9,strF1,strF2,strF3,strF4,strF5    ; set color step
  238.     dw    strF6,strF7,strF8,strF9
  239. strG    dw    4,strG1,strG2,strG3,strG4    ; gradation menu
  240. ;
  241. str11    dw    TITX+(TITW-30*8)/2,TITY+19,30
  242.     db    "マンデルブロ図形描画プログラム"
  243. str20    dw    SCRX+(SCRW-28*8)/2,SCRY+(SCRH-16)/2+16,28
  244.     db    "RUNボタンを押してください"
  245. str29    dw    SCRX+(SCRW-10*8)/2,SCRY+30,10
  246.     db    "Volume One"
  247. str21    dw    SCRX+(SCRW-19*8)/2,SCRY+58,19
  248.     db    "MANDEL.EXP"
  249. str22    dw    SCRX+(SCRW-11*8)/2,SCRY+82,11
  250.     db    "Version 1.0"
  251. str23    dw    SCRX+(SCRW-16*8)/2,SCRY+124,16
  252.     db    "このプログラムは"
  253. str24    dw    SCRX+(SCRW-28*8)/2,SCRY+148,28
  254.     db    "TOWNSパッドで操作します"
  255. str25    dw    SCRX+(SCRW-40*8)/2,SCRY+270,40
  256.     db    "本プログラムの無断複製・譲渡を許可します"
  257. str26    dw    SCRX+(SCRW-38*8)/2,SCRY+294,38
  258.     db    "但し著作権を放棄するものではありません"
  259. str27    dw    SCRX+(SCRW-26*8)/2,SCRY+346,26
  260.     db    "Copyright (C) 1990 by Fumi"
  261. str28    dw    SCRX+(SCRW-35*8)/2,SCRY+370,35
  262.     db    "Special Thanks to Oh!FM and FUJITSU"
  263. str31    dw    MENUX+(MENUW-6*8)/2,MENUY+20,6
  264.     db    "描画中"        ; on drawing title
  265. str32    dw    MENUX+(MENUW-8*8)/2,MENUY+80,8
  266.     db    "描画間隔"
  267. str411    dw    PARX+3,PARY+18,6
  268.     db    "左上X"
  269. str412    dw    PARX+3,PARY+36,6
  270.     db    "左上Y"
  271. str413    dw    PARX+3,PARY+54,6
  272.     db    "分解能"
  273. str414    dw    PARX+3,PARY+72,8
  274.     db    "上限回数"
  275. str421    dw    PTX+25,PTY+15,2
  276.     db    "+1"
  277. str422    dw    PTX+112,PTY+15,3
  278.     db    "+25"
  279. str431    dw    PTX+10,PTY+30,1
  280.     db    "0"
  281. str432    dw    PTX+7,PTY+50,2
  282.     db    "50"
  283. str433    dw    PTX+3,PTY+70,3
  284.     db    "100"
  285. str434    dw    PTX+3,PTY+90,3
  286.     db    "150"
  287. str435    dw    PTX+3,PTY+110,3
  288.     db    "200"
  289. str51    dw    MENUX+(MENUW-14*8)/2,MENUY+30,14
  290.     db    "SELECTボタンで"
  291. str52    dw    MENUX+(MENUW-10*8)/2,MENUY+50,10
  292.     db    "メニューへ"
  293. str53    dw    MENUX+(MENUW-12*8)/2,MENUY+80,12
  294.     db    "移動ボタンで"
  295. str54    dw    MENUX+(MENUW-10*8)/2,MENUY+100,10
  296.     db    "スクロール"
  297. str55    dw    MENUX+(MENUW-10*8)/2,MENUY+130,10
  298.     db    "Aボタンで"
  299. str56    dw    MENUX+(MENUW-8*8)/2,MENUY+150,8
  300.     db    "描画続行"
  301. str61    dw    MENUX+(MENUW-5*8)/2,MENUY+20,5
  302.     db    "拡 大"
  303. str62    dw    MENUX+10,MENUY+48,4
  304.     db    "枠X"
  305. str63    dw    MENUX+10,MENUY+66,4
  306.     db    "枠Y"
  307. str64    dw    MENUX+(MENUW-10*8)/2,MENUY+94,10
  308.     db    "RUN 枠拡大"
  309. str65    dw    MENUX+(MENUW-10*8)/2,MENUY+116,10
  310.     db    "SEL 枠縮小"
  311. str71    dw    MENUX+(MENUW-8*8)/2,MENUY+20,8
  312.     db    "上限回数"        ; change limit menu title
  313. str72    dw    MENUX+20,MENUY+46,6
  314.     db    "現在値"
  315. str73    dw    MENUX+20,MENUY+66,6
  316.     db    "変更値"
  317. strF4    label    word
  318. str74    dw    MENUX+(MENUW-10*8)/2,MENUY+89,10
  319.     db    "↑ ↓ 増減"
  320. str77    dw    MENUX+(MENUW-12*8)/2,MENUY+112,12
  321.     db    "RUN 自動追加"
  322. str78    dw    MENUX+(MENUW-12*8)/2,MENUY+134,12
  323.     db    "SEL 自動増加"
  324. str81    dw    MENUX+(MENUW-8*8)/2,MENUY+20,8
  325.     db    "自動追加"
  326. strU2    label    word
  327. str82    dw    MENUX+(MENUW-8*8)/2,MENUY+80,8
  328.     db    "上限回数"
  329. strU1    dw    MENUX+(MENUW-8*8)/2,MENUY+20,8
  330.     db    "自動増加"
  331. str91    dw    MENUX+(MENUW-6*8)/2,MENUY+20,6
  332.     db    "色設定"        ; change color menu title
  333. str92    dw    MENUX+(MENUW-11*8)/2,MENUY+175,11
  334.     db    "↑ ↓ A B"        ; cahnge color menu button
  335. strA1    dw    MENUX+(MENUW-10*8)/2,MENUY+20,10
  336.     db    "色番号選択"        ; change individual color menu title
  337. strA2    dw    MENUX+10,MENUY+63,2
  338.     db    "←"
  339. strA3    dw    MENUX+MENUW-26,MENUY+63,2
  340.     db    "→"
  341. strRGB    label    word        ; for indc
  342. strRGBL    equ    8        ; for indc
  343. strC2    label    word
  344. strB2    label    word
  345. strA4    dw    MENUX+12,MENUY+92,2
  346.     db    "B"
  347. strC3    label    word
  348. strB3    label    word
  349. strA5    dw    MENUX+12,MENUY+108,2
  350.     db    "R"
  351. strC4    label    word
  352. strB4    label    word
  353. strA6    dw    MENUX+12,MENUY+124,2
  354.     db    "G"
  355. strA7    dw    MENUX+18,MENUY+156,3
  356.     db    "SEL"
  357. strA8    dw    MENUX+14,MENUY+178,4
  358.     db    "抽出"
  359. strU3    label    word
  360. str83    label    word
  361. strG3    label    word
  362. str66    label    word
  363. str75    label    word
  364. strF8    label    word
  365. strC5    label    word
  366. strA9    dw    MENUX+MENUW/2+8,MENUY+156,7
  367.     db    "A 決定"
  368. strU4    label    word
  369. str84    label    word
  370. str33    label    word
  371. strG4    label    word
  372. str67    label    word
  373. str76    label    word
  374. strF9    label    word
  375. strB7    label    word
  376. strC6    label    word
  377. strA10    dw    MENUX+MENUW/2+8,MENUY+178,7
  378.     db    "B 中止"
  379. strB1    dw    MENUX+(MENUW-6*8)/2,MENUY+20,6
  380.     db    "色編集"    ; edit color menu title
  381. strB5    dw    MENUX+10,MENUY+146,10
  382.     db    "SEL  ← →"
  383. strB6    dw    MENUX+10,MENUY+178,7
  384.     db    "A 決定"
  385. strC1    dw    MENUX+(MENUW-6*8)/2,MENUY+20,6
  386.     db    "色抽出"    ; extract pallet number menu title
  387. strD1    dw    MENUX+(MENUW-5*8)/2,MENUY+20,5
  388.     db    "保 存"        ; save menu title
  389. strD2    dw    MENUX+(MENUW-10*8)/2,MENUY+50,10
  390.     db    "ファイル名"
  391. strD3    dw    MENUX+(MENUW-11*8)/2+8,MENUY+120,10
  392.     db    "CR A 決定"
  393. strD4    dw    MENUX+(MENUW-11*8)/2,MENUY+146,11
  394.     db    "ESC B 中止"
  395. strE1    dw    MENUX+(MENUW-8*8)/2,MENUY+20,8
  396.     db    "読み込み"    ; load menu title
  397. strE2    dw    MENUX+106,MENUY+67,2
  398.     db    "↑"
  399. strE3    dw    MENUX+106,MENUY+89,2
  400.     db    "↓"
  401. strE4    dw    MENUX+106,MENUY+138,2
  402.     db    "A"
  403. strE5    dw    MENUX+106,MENUY+160,2
  404.     db    "B"
  405. strF1    dw    MENUX+(MENUW-6*8)/2,MENUY+20,6
  406.     db    "色間隔"    ; set color step menu title
  407. strF2    dw    MENUX+20,MENUY+46,6
  408.     db    "増単位"
  409. strF3    dw    MENUX+20,MENUY+66,6
  410.     db    "色間隔"
  411. strF5    dw    MENUX+(MENUW-10*8)/2,MENUY+114,10
  412.     db    "← → 単位"
  413. strF6    dw    MENUX+18,MENUY+156,3
  414.     db    "RUN"
  415. strF7    dw    MENUX+14,MENUY+178,4
  416.     db    "自動"
  417. strG1    dw    MENUX+(MENUW-14*8)/2,MENUY+20,14
  418.     db    "グラデーション"    ; gradation menu title
  419. strG2    dw    MENUX+66-24,MENUY+90,9
  420.     db    "← SEL →"
  421. ;
  422. but1N    equ    5        ; zoom up command button data
  423. but1    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; 拡大
  424.     butstr    <(MENUY+94-18)*VRAMW+MENUX+(MENUW-10*8)/2-2,28,20>    ; RUN
  425.     butstr    <(MENUY+116-18)*VRAMW+MENUX+(MENUW-10*8)/2-2,28,20>    ; SEL
  426.     butstr    <(MENUY+138)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; A
  427.     butstr    <(MENUY+160)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; B
  428. but2N    equ    7        ; change limit command button
  429. but2    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; 上限回数
  430.     butstr    <(MENUY+72)*VRAMW+MENUX+(MENUW-10*8)/2-2,20,20>        ; ↑
  431.     butstr    <(MENUY+72)*VRAMW+MENUX+(MENUW-10*8)/2+3*8-2,20,20>    ; ↓
  432.     butstr    <(MENUY+94)*VRAMW+MENUX+(MENUW-12*8)/2-2,28,20>        ; RUN
  433.     butstr    <(MENUY+116)*VRAMW+MENUX+(MENUW-12*8)/2-2,28,20>    ; SEL
  434.     butstr    <(MENUY+138)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; A
  435.     butstr    <(MENUY+160)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; B
  436. butdN    equ    2        ; on drawing message button
  437. butUN    equ    3        ; automatically limit up
  438. butAN    equ    3        ; automatically limit addition
  439. butd    label    byte
  440. butU    label    byte
  441. butA    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>; 自動追加/自動増加/描画中
  442.     butstr    <(MENUY+160)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; B
  443.     butstr    <(MENUY+138)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; A
  444. but3N    equ    4        ; change color menu button
  445. but3    butstr    <(MENUY+175-17)*VRAMW+MENUX+(MENUW-11*8)/2-2,20,20>    ; ↑
  446.     butstr    <(MENUY+175-17)*VRAMW+MENUX+(MENUW-11*8)/2+3*8-2,20,20>    ; ↓
  447.     butstr    <(MENUY+175-17)*VRAMW+MENUX+(MENUW-11*8)/2+6*8-2,20,20>    ; A
  448.     butstr    <(MENUY+175-17)*VRAMW+MENUX+(MENUW-11*8)/2+9*8-2,20,20>    ; B
  449. but4N    equ    8        ; change color command button
  450. but4    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; 色番号選択
  451.     butstr    <(MENUY+45)*VRAMW+MENUX+(MENUW-78)/2,78,20>    ; color box
  452.     butstr    <(MENUY+45)*VRAMW+MENUX+10-2,20,20>        ; ←
  453.     butstr    <(MENUY+45)*VRAMW+MENUX+MENUW-26-2,20,20>    ; →
  454.     butstr    <(MENUY+74)*VRAMW+MENUX+(MENUW-70)/2,70,52>    ; bar frame
  455.     butstr    <(MENUY+138)*VRAMW+MENUX+18-2,28,20>        ; SEL
  456.     butstr    <(MENUY+138)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; A
  457.     butstr    <(MENUY+160)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; B
  458. but5N    equ    8        ; edit color button
  459. but5    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; 色編集
  460.     butstr    <(MENUY+45)*VRAMW+MENUX+(MENUW-78)/2,78,20>    ; color box
  461.     butstr    <(MENUY+74)*VRAMW+MENUX+(MENUW-70)/2,70,52>    ; bar frame
  462.     butstr    <(MENUY+146-18)*VRAMW+MENUX+10-2,28,20>        ; SEL
  463.     butstr    <(MENUY+146-18)*VRAMW+MENUX+10+5*8-2,20,20>    ; ←
  464.     butstr    <(MENUY+146-18)*VRAMW+MENUX+10+8*8-2,20,20>    ; →
  465.     butstr    <(MENUY+160)*VRAMW+MENUX+10-2,20,20>        ; A
  466.     butstr    <(MENUY+160)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; B
  467. but6N    equ    5        ; extract pallet number button
  468. but6    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; 色抽出
  469.     butstr    <(MENUY+45)*VRAMW+MENUX+(MENUW-78)/2,78,20>    ; color box
  470.     butstr    <(MENUY+74)*VRAMW+MENUX+(MENUW-70)/2,70,52>    ; bar frame
  471.     butstr    <(MENUY+138)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; A
  472.     butstr    <(MENUY+160)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; B
  473. but7N    equ    6        ; save menu button
  474. but7    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; 保 存
  475.     butstr    <(MENUY+80-18)*VRAMW+MENUX+(MENUW-80)/2,80,20>    ; for file name
  476.     butstr    <(MENUY+120-18)*VRAMW+MENUX+(MENUW-11*8)/2+8-2,2*8+4,20>; CR
  477.     butstr    <(MENUY+120-18)*VRAMW+MENUX+(MENUW-11*8)/2+4*8-2,2*8+4,20>; A
  478.     butstr    <(MENUY+146-18)*VRAMW+MENUX+(MENUW-11*8)/2-2,3*8+4,20>    ; ESC
  479.     butstr    <(MENUY+146-18)*VRAMW+MENUX+(MENUW-11*8)/2+4*8-2,2*8+4,20>; B
  480. but8N    equ    6        ; load menu button
  481. but8    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; 読み込み
  482.     butstr    <(MENUY+33)*VRAMW+MENUX+20,10*8,8*18+2>; file name
  483.     butstr    <(MENUY+67-17)*VRAMW+MENUX+104,20,20>    ; ↑
  484.     butstr    <(MENUY+89-17)*VRAMW+MENUX+104,20,20>    ; ↓
  485.     butstr    <(MENUY+138-18)*VRAMW+MENUX+104,20,20>    ; A
  486.     butstr    <(MENUY+160-18)*VRAMW+MENUX+104,20,20>    ; B
  487. but9N    equ    8        ; set color step menu button
  488. but9    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; 色間隔
  489.     butstr    <(MENUY+72)*VRAMW+MENUX+(MENUW-10*8)/2-2,20,20>        ; ↑
  490.     butstr    <(MENUY+72)*VRAMW+MENUX+(MENUW-10*8)/2+3*8-2,20,20>    ; ↓
  491.     butstr    <(MENUY+96)*VRAMW+MENUX+(MENUW-10*8)/2-2,20,20>        ; ←
  492.     butstr    <(MENUY+96)*VRAMW+MENUX+(MENUW-10*8)/2+3*8-2,20,20>    ; →
  493.     butstr    <(MENUY+138)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; A
  494.     butstr    <(MENUY+160)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; B
  495.     butstr    <(MENUY+138)*VRAMW+MENUX+18-2,28,20>        ; RUN
  496. butGN    equ    8        ; gradation menu button
  497. butG    butstr    <(MENUY+3)*VRAMW+MENUX+3,MENUW-6,20>    ; グラデーション"
  498.     butstr    <(MENUY+60-17)*VRAMW+MENUX+40-2,80,20>        ; 1 color
  499.     butstr    <(MENUY+120-17)*VRAMW+MENUX+40-2,80,20>        ; 250 color
  500.     butstr    <(MENUY+90-17)*VRAMW+MENUX+66-24-2,20,20>    ; ←
  501.     butstr    <(MENUY+90-17)*VRAMW+MENUX+66-2,28,20>        ; SEL
  502.     butstr    <(MENUY+90-17)*VRAMW+MENUX+66+32-2,20,20>    ; →
  503.     butstr    <(MENUY+138)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; A
  504.     butstr    <(MENUY+160)*VRAMW+MENUX+MENUW/2+8-2,20,20>    ; B
  505. ;
  506. simain    dw    0,9        ; selector item in main menu
  507.     dw    simain0,simain1,simain2,simain3,simain4
  508.     dw    simain5,simain6,simain7,simain8
  509. sicol    dw    0,6        ; selector item in color menu
  510.     dw    sicol0,sicol1,sicol2,sicol3,sicol4,sicol5
  511. ;
  512. simain0    dw    MENUX+(MENUW-5*8)/2,MENUY+19,5
  513.     db    "拡 大"
  514. simain1    dw    MENUX+(MENUW-5*8)/2,MENUY+39,5
  515.     db    "縮 小"
  516. simain2    dw    MENUX+(MENUW-6*8)/2,MENUY+59,6
  517.     db    "全体図"
  518. simain3    dw    MENUX+(MENUW-6*8)/2,MENUY+79,6
  519.     db    "色設定"
  520. simain4    dw    MENUX+(MENUW-8*8)/2,MENUY+99,8
  521.     db    "上限回数"
  522. simain5    dw    MENUX+(MENUW-8*8)/2,MENUY+119,8
  523.     db    "読み込み"
  524. simain6    dw    MENUX+(MENUW-5*8)/2,MENUY+139,5
  525.     db    "保 存"
  526. simain7    dw    MENUX+(MENUW-8*8)/2,MENUY+159,8
  527.     db    "描画続行"
  528. simain9    dw    MENUX+(MENUW-10*8)/2,MENUY+159,10
  529.     db    "スクロール"
  530. simain8    dw    MENUX+(MENUW-14*8)/2,MENUY+179,14
  531.     db    "プログラム終了"
  532. ;
  533. sicol0    dw    MENUX+(MENUW-8*8)/2,MENUY+44,8
  534.     db    "個別設定"
  535. sicol1    dw    MENUX+(MENUW-6*8)/2,MENUY+64,6
  536.     db    "色間隔"
  537. sicol2    dw    MENUX+(MENUW-14*8)/2,MENUY+84,14
  538.     db    "グラデーション"
  539. sicol3    dw    MENUX+(MENUW-8*8)/2,MENUY+104,8
  540.     db    "読み込み"
  541. sicol4    dw    MENUX+(MENUW-5*8)/2,MENUY+124,5
  542.     db    "保 存"
  543. sicol5    dw    MENUX+(MENUW-5*8)/2,MENUY+144,5
  544.     db    "復 元"
  545. data    ends
  546.  
  547. code    segment    use32 eo
  548.     assume    cs:code,ds:data
  549.  
  550. entry:    mov    ax,0110h    ; TOWNS BIOS
  551.     mov    fs,ax
  552. ;-------------------------------
  553. ; Initialize CRTC & data
  554. ;-------------------------------
  555.     mov    edi,offset egbwork    ; initialize EGB
  556.     mov    ecx,EGBSIZ
  557.     xor    ah,ah
  558.     call    pword ptr fs:[20h]
  559.     mov    ax,0100h        ; set virtual screen
  560.     mov    dx,12
  561.     call    pword ptr fs:[20h]
  562.     mov    ax,0701h        ; set background color
  563.     mov    edx,C$DARK
  564.     call    pword ptr fs:[20h]
  565. ;
  566.     mov    esi,offset syspal    ; pallet packet address
  567.     mov    ecx,syspalN
  568. init10:    call    setpal            ; set pallet
  569.     add    esi,4
  570.     loop    init10
  571. ;
  572.     mov    edi,offset palbuf    ; pallet data buffer
  573.     mov    dword ptr [edi],0    ; pallet number = 0
  574.     mov    esi,offset palpkt    ; set display pallet
  575.     mov    eax,0FFFFFFh/100
  576.     mov    ecx,USRCN
  577.     mov    dword ptr bpal,0
  578. init12:    add    dword ptr bpal,eax
  579.     call    setpal
  580.     add    edi,3
  581.     mov    dx,word ptr bpal
  582.     mov    [edi],dx
  583.     mov    dl,gpal
  584.     mov    [edi+2],dl
  585.     inc    palnum
  586.     loop    init12
  587. ;-------------------------------
  588. ; save parameter & set
  589. ; in : es = stack & data segment
  590. ;-------------------------------
  591.     push    ds
  592.     mov    ax,0004h    ; PSP selector
  593.     mov    ds,ax
  594.     mov    esi,80h            ; command line address
  595.     mov    edi,offset pathbuf    ; saving address
  596.     movzx    ecx,byte ptr [esi]    ; string length
  597.     movsb                ; save string length
  598.     rep    movsb            ; save command line string
  599. ;
  600.     mov    eax,ds:[0000005Ch]    ; necessary size
  601.     mov    edx,ds:[00000060h]    ; program size
  602.     pop    ds
  603.     add    eax,11b        ; round up to 4 times
  604.     and    al,111100b
  605.     mov    buffer,eax    ; save calculate data buffer pointer
  606.     sub    edx,eax
  607.     mov    bufsiz,edx    ; save buffer size
  608. ;
  609.     push    ds
  610.     xor    ax,ax        ; read ANK font address
  611.     mov    dx,0810h    ; 8*16 dot
  612.     xor    bl,bl        ; ANK code = 0
  613.     call    pword ptr fs:[0A0h]    ; call font BIOS
  614.     mov    ss:ankfnt,esi    ; font offset
  615.     mov    word ptr ss:ankfnt[4],ds    ; font selector
  616.     pop    ds
  617. ;-------------------------------
  618. ; starting screen
  619. ;-------------------------------
  620.     mov    ax,0128h    ; TOWNS VRAM (1 screen mode)
  621.     mov    es,ax
  622. ;
  623.     mov    esi,offset bgblock
  624.     xor    edi,edi
  625.     mov    count1,BGBH    ; set block hight counter
  626. init30:    mov    dx,BGBLN    ; set block line counter
  627. init32:    mov    bx,BGBCN    ; set block column counter
  628. init34:    mov    ecx,BGBW/2
  629.     rep    movsw        ; display 1 line of block
  630.     sub    esi,BGBW    ; rewind source line address
  631.     dec    bx        ; decrese block column counter
  632.     jnz    init34
  633.     add    edi,BGBH*VRAMW-BGBW*BGBCN    ; next destination address
  634.     dec    dx
  635.     jnz    init32
  636.     add    esi,BGBW
  637.     sub    edi,BGBLN*BGBH*VRAMW-VRAMW
  638.     dec    count1
  639.     jnz    init30
  640. ;
  641.     mov    esi,offset titbox    ; title box clear
  642.     mov    al,C$PANEL
  643.     call    boxdwn
  644.     mov    esi,offset scrbox    ; screen box clear
  645.     mov    al,C$PANEL
  646.     call    boxdwn
  647. ;
  648.     mov    edi,offset egbwork    ; work address
  649.     mov    ah,19h            ; set font style
  650.     mov    dx,100b            ; shadow
  651.     call    pword ptr fs:[20h]
  652.     mov    bx,offset str1        ; title string index
  653.     mov    al,C$BLOCK
  654.     call    dspss
  655. ;
  656.     mov    ah,19h            ; set font style
  657.     xor    dx,dx            ; standard
  658.     call    pword ptr fs:[20h]
  659.     mov    bx,offset str2        ; starting message index
  660.     mov    al,C$DARK        ; string color
  661.     call    dspss            ; display strings
  662.     mov    al,C$INT        ; string color
  663.     call    color
  664.     mov    esi,offset str20    ; "press RUN button"
  665.     mov    ah,60h
  666.     call    pword ptr fs:[20h]
  667. ;-------------------------------
  668. ; calculate initial screen
  669. ;-------------------------------
  670.     mov    ebp,offset idata    ; save address
  671.     mov    count1,SCRH/2    ; set screen hight counter
  672.     mov    curb,IPOSY+IRESO*SCRH/2    ; set y start position
  673. init40:    call    getpad        ; get pad button state
  674.     cmp    al,P$RUN    ; check press RUN button
  675.     je    init60        ; press to intterrupt
  676.     mov    count2,SCRW    ; set screen width counter
  677.     mov    cura,IPOSX    ; set x start position
  678. init42:    push    ebp
  679.     call    calc        ; calculate repeat number
  680.     pop    ebp
  681.     mov    [ebp],al    ; save to memory
  682.     inc    ebp        ; next memory address
  683.     add    cura,IRESO    ; next x position
  684.     dec    count2
  685.     jnz    init42
  686.     inc    islin        ; line calculated counter up
  687.     add    curb,IRESO    ; set next y position
  688.     dec    count1
  689.     jne    init40
  690. ;
  691. init48:    call    getpad        ; get pad button state
  692.     cmp    al,P$RUN    ; wait RUN button press
  693.     jne    init48
  694. ;-------------------------------
  695. ; display rest initial screen
  696. ;-------------------------------
  697. init60:    mov    esi,offset parbox    ; parameter box clear
  698.     mov    al,C$PANEL
  699.     call    boxdwn
  700.     mov    esi,offset palbox    ; pallet box clear
  701.     mov    al,C$PANEL
  702.     call    boxdwn
  703. ;
  704.     mov    edi,PTBADR-2*VRAMW-2    ; pallet table address
  705.     mov    ax,PTBCN*PTBW+4        ; table width
  706.     mov    dx,PTBLN*PTBH+3        ; table hight
  707.     call    boxup            ; look like box up
  708. ;
  709.     mov    dx,PTBLN    ; pallet block line number counter
  710.     xor    al,al        ; initialize pallet number
  711.     mov    edi,PTBADR    ; VRAM start address
  712. init62:    mov    bx,PTBH-1    ; block lines counter
  713. init64:    mov    ecx,PTBCN    ; block column number
  714. init66:    inc    al
  715.     mov    ah,al
  716.     stosw
  717.     stosw
  718.     loop    init66
  719.     add    edi,VRAMW-PTBW*PTBCN
  720.     sub    al,PTBCN
  721.     dec    bx
  722.     jnz    init64
  723.     add    edi,VRAMW    ; skip 1 line
  724.     add    al,PTBCN
  725.     dec    dx
  726.     jnz    init62
  727. ;
  728.     mov    bx,offset str4    ; strings index
  729.     mov    al,C$DARK    ; dark shadow color
  730.     call    dspss
  731. ;-------------------------------
  732. ; display mandelbrot figure
  733. ;-------------------------------
  734.     call    dspis        ; display initial screen
  735. main10:    call    dspmain        ; display main mandelbrot figure
  736. ;-------------------------------
  737. ; scroll mode
  738. ;-------------------------------
  739. main20:    mov    esi,offset menubox    ; menu box clear
  740.     mov    al,C$PANEL
  741.     call    boxdwn
  742.     mov    bx,offset str5    ; scroll mode message index
  743.     mov    ax,6        ; on drawing message numbers
  744.     cmp    curstat,DS$FULL    ; check display state
  745.     jne    main21
  746.     mov    ax,4        ; message numbers on completion
  747. main21:    mov    [bx],ax        ; set message numbers
  748.     mov    al,C$INT    ; string color
  749.     call    dspss        ; display messages
  750. ;
  751.     xor    ax,ax        ; wait no press state
  752.     call    waitp
  753. main22:    call    getpad        ; get pad state
  754.     test    ah,P$TRIG1
  755.     jnz    main10        ; continue display
  756.     cmp    al,P$SEL
  757.     je    main30        ; go to menu mode
  758.     cmp    al,P$FWD
  759.     je    main24        ; go to scroll down
  760.     cmp    al,P$BACK
  761.     je    main26        ; go to scroll up
  762.     cmp    al,P$LEFT
  763.     je    main28        ; go to scroll right
  764.     cmp    al,P$RIGHT
  765.     jne    main22        ; go to get new state
  766. ;
  767.     call    srlft        ; scroll left
  768.     jmp    main22
  769. main24:    call    srdwn        ; scroll down
  770.     jmp    main22
  771. main26:    call    srup        ; scroll up
  772.     jmp    main22
  773. main28:    call    srrgt        ; scroll right
  774.     jmp    main22
  775. ;-------------------------------
  776. ; menu mode
  777. ;-------------------------------
  778. main30:    mov    esi,offset menubox
  779.     mov    al,C$PANEL
  780.     call    boxdwn        ; menu box clear
  781.     mov    bx,offset simain    ; selector data address
  782.     mov    ax,offset simain7
  783.     cmp    curstat,DS$FULL
  784.     jne    main32
  785.     mov    ax,offset simain9
  786. main32:    mov    [bx+18],ax
  787.     call    select        ; select item
  788.     jc    main20        ; escape to scroll mode
  789.     shl    ax,2        ; make offset
  790.     cwde
  791.     jmp    cmdtbl1[eax]    ; jump destination procedure
  792. ;-------------------------------
  793. ; procedures for exit
  794. ;-------------------------------
  795. main99:    mov    ax,4C00h        ; exit to DOS
  796.     int    21h
  797.  
  798. ;*******************************
  799. ; srdwn : scroll down
  800. ;
  801. ; in : step = half scroll step
  802. ;           (0 is 1 step)
  803. ; call: dspbl,putfp
  804. ; use: eax,ebx,ecx,edx,esi,edi,ebp
  805. ;
  806. srdwn    proc
  807. ;-------------------------------
  808. ; calculate new position
  809. ;-------------------------------
  810.     movzx    ebx,step    ; current dispaling step
  811.     shl    ebx,1        ; scroll step
  812.     jnz    srdw10
  813.     inc    ebx        ; scroll step = 1
  814. srdw10:    mov    eax,ebx
  815.     mul    reso        ; scroll amount
  816.     sub    posy,eax    ; new y position
  817.     cmp    posy,-2 shl 24    ; check lower limit
  818.     jge    srdw20        ; OK!
  819.     add    posy,eax    ; recover
  820.     ret
  821. ;-------------------------------
  822. ; display new y position
  823. ;-------------------------------
  824. srdw20:    push    ebx
  825.     mov    eax,posy    ; new position y
  826.     neg    eax
  827.     mov    edi,LPOSY    ; display position
  828.     call    putfp
  829.     pop    ebx
  830. ;-------------------------------
  831. ; move down current screen
  832. ; in : ebx = scroll step
  833. ;-------------------------------
  834.     mov    edi,(SCRY+SCRH-1)*VRAMW+SCRX
  835.     mov    esi,edi
  836.     imul    eax,ebx,VRAMW
  837.     sub    esi,eax        ; source start address
  838.     mov    dx,SCRH
  839.     sub    dx,bx        ; move line counter
  840. srdw40:    mov    ecx,SCRW/4
  841.     rep    movs    dword ptr [edi],es:[esi]
  842.     sub    esi,SCRW+VRAMW
  843.     sub    edi,SCRW+VRAMW
  844.     dec    dx
  845.     jnz    srdw40
  846. ;-------------------------------
  847. ; display block line
  848. ; in : ebx = scroll step
  849. ;-------------------------------
  850.     mov    edi,SCRADR
  851.     mov    eax,posy    ; start y position
  852.     mov    curb,eax
  853.     call    dspbl        ; display block line
  854.     ret
  855. srdwn    endp
  856.  
  857. ;*******************************
  858. ; srup : scroll up
  859. ;
  860. ; in : step = half scroll step
  861. ;           (0 is 1 step)
  862. ; call: dspbl,putfp
  863. ; use: eax,ebx,ecx,edx,esi,edi,ebp
  864. ;
  865. srup    proc
  866. ;-------------------------------
  867. ; calculate new position
  868. ;-------------------------------
  869.     movzx    ebx,step    ; current dispaling step
  870.     shl    ebx,1        ; scroll step
  871.     jnz    srup10
  872.     inc    ebx        ; scroll step = 1
  873. srup10:    mov    eax,ebx
  874.     mul    reso        ; scroll amount
  875.     imul    edx,reso,SCRH
  876.     add    edx,posy
  877.     add    edx,eax
  878.     cmp    edx,2 shl 24    ; check uppper limit
  879.     jg    srup90        ; over
  880.     add    posy,eax    ; new y position
  881. ;-------------------------------
  882. ; display new y position
  883. ;-------------------------------
  884.     push    ebx
  885.     mov    eax,posy    ; new position y
  886.     neg    eax
  887.     mov    edi,LPOSY    ; display position
  888.     call    putfp
  889.     pop    ebx
  890. ;-------------------------------
  891. ; move up current screen
  892. ; in : ebx = scroll step
  893. ;-------------------------------
  894.     mov    edi,SCRADR
  895.     imul    esi,ebx,VRAMW
  896.     add    esi,edi        ; source start address
  897.     mov    dx,SCRH
  898.     sub    dx,bx        ; move line counter
  899. srup20:    mov    ecx,SCRW/4
  900.     rep    movs    dword ptr [edi],es:[esi]
  901.     add    esi,-SCRW+VRAMW
  902.     add    edi,-SCRW+VRAMW
  903.     dec    dx
  904.     jnz    srup20
  905. ;-------------------------------
  906. ; display block line
  907. ; in : ebx = scroll step
  908. ;      edi = block line address
  909. ;-------------------------------
  910.     mov    eax,SCRH    ; screen hight
  911.     sub    eax,ebx        ; screen position
  912.     mul    reso        ; offset y position
  913.     add    eax,posy    ; start y position
  914.     mov    curb,eax
  915.     call    dspbl        ; display block line
  916. srup90:    ret
  917. srup    endp
  918.  
  919. ;*******************************
  920. ; srrgt : scroll right
  921. ;
  922. ; in : step = half scroll step
  923. ;           (0 is 1 step)
  924. ; call: putfp,dspbc
  925. ; use: eax,ebx,ecx,edx,esi,edi,ebp
  926. ;
  927. srrgt    proc
  928. ;-------------------------------
  929. ; calculate new position
  930. ;-------------------------------
  931.     movzx    ebx,step    ; current dispaling step
  932.     shl    ebx,1        ; scroll step
  933.     jnz    srrt10
  934.     inc    ebx        ; scroll step = 1
  935. srrt10:    mov    eax,ebx
  936.     mul    reso        ; scroll amount
  937.     sub    posx,eax    ; new x position
  938.     cmp    posx,-2 shl 24    ; check lower limit
  939.     jge    srrt20        ; OK!
  940.     add    posx,eax    ; recover
  941.     ret
  942. ;-------------------------------
  943. ; display new x position
  944. ;-------------------------------
  945. srrt20:    push    ebx
  946.     mov    eax,posx    ; new position x
  947.     mov    edi,LPOSX    ; display position
  948.     call    putfp
  949.     pop    ebx
  950. ;-------------------------------
  951. ; move right current screen
  952. ; in : ebx = scroll step
  953. ;-------------------------------
  954.     std            ; set direction flag
  955.     mov    edi,SCRY*VRAMW+SCRX+SCRW-4
  956.     mov    esi,edi
  957.     sub    esi,ebx        ; source start address
  958.     mov    eax,SCRW    ; screen width
  959.     sub    eax,ebx        ; move width
  960.     mov    ebp,eax
  961.     add    ebp,VRAMW-3    ; VRAM step
  962.     mov    dx,SCRH        ; move line counter
  963.     push    ebx
  964.     mov    ebx,eax
  965.     shr    eax,2
  966.     and    ebx,11b
  967. srrt30:    mov    ecx,eax        ; set column counter
  968.     rep    movs    dword ptr [edi],es:[esi]
  969.     add    esi,3
  970.     add    edi,3
  971.     mov    ecx,ebx
  972.     rep    movs    byte ptr [edi],es:[esi]
  973.     add    esi,ebp        ; next line
  974.     add    edi,ebp
  975.     dec    dx
  976.     jnz    srrt30
  977.     pop    ebx
  978.     cld            ; clear direction flag
  979. ;-------------------------------
  980. ; display block column
  981. ; in : ebx = scroll step
  982. ;-------------------------------
  983.     mov    edi,SCRADR
  984.     mov    eax,posx    ; start x position
  985.     mov    cura,eax
  986.     call    dspbc        ; display block column
  987.     ret
  988. srrgt    endp
  989.  
  990. ;*******************************
  991. ; srlft : scroll left
  992. ;
  993. ; in : step = half scroll step
  994. ;           (0 is 1 step)
  995. ; call: putfp,dspbc
  996. ; use: eax,ebx,ecx,edx,esi,edi,ebp
  997. ;
  998. srlft    proc
  999. ;-------------------------------
  1000. ; calculate new position
  1001. ;-------------------------------
  1002.     movzx    ebx,step    ; current dispaling step
  1003.     shl    ebx,1        ; scroll step
  1004.     jnz    srlt10
  1005.     inc    ebx        ; scroll step = 1
  1006. srlt10:    mov    eax,ebx
  1007.     mul    reso        ; scroll amount
  1008.     imul    edx,reso,SCRW
  1009.     add    edx,posx
  1010.     add    edx,eax
  1011.     cmp    edx,2 shl 24    ; check uppper limit
  1012.     jg    srlt90        ; over
  1013.     add    posx,eax    ; new x position
  1014. ;-------------------------------
  1015. ; display new x position
  1016. ;-------------------------------
  1017.     push    ebx
  1018.     mov    eax,posx    ; new position x
  1019.     mov    edi,LPOSX    ; display position
  1020.     call    putfp
  1021.     pop    ebx
  1022. ;-------------------------------
  1023. ; move left current screen
  1024. ; in : ebx = scroll step
  1025. ;-------------------------------
  1026.     push    ebx
  1027.     mov    edi,SCRADR
  1028.     mov    esi,edi
  1029.     add    esi,ebx        ; source start address
  1030.     mov    eax,SCRW    ; screen width
  1031.     sub    eax,ebx        ; move width
  1032.     mov    ebp,VRAMW
  1033.     sub    ebp,eax        ; VRAM step
  1034.     mov    dx,SCRH        ; move line counter
  1035.     mov    ebx,eax
  1036.     shr    eax,2
  1037.     and    ebx,11b
  1038. srlt22:    mov    ecx,eax        ; set column counter
  1039.     rep    movs    dword ptr [edi],es:[esi]
  1040.     mov    ecx,ebx
  1041.     rep    movs    byte ptr [edi],es:[esi]
  1042.     add    esi,ebp        ; next line
  1043.     add    edi,ebp
  1044.     dec    dx
  1045.     jnz    srlt22
  1046.     pop    ebx
  1047. ;-------------------------------
  1048. ; display block column
  1049. ; in : ebx = scroll step
  1050. ;-------------------------------
  1051.     mov    edi,SCRADR+SCRW
  1052.     sub    edi,ebx        ; block VRAM address
  1053.     mov    eax,SCRW
  1054.     sub    eax,ebx
  1055.     mul    reso
  1056.     add    eax,posx    ; start x position
  1057.     mov    cura,eax
  1058.     call    dspbc        ; display block column
  1059. srlt90:    ret
  1060. srlft    endp
  1061.  
  1062. ;*******************************
  1063. ; zoomin : zoom in command
  1064. ;*******************************
  1065. zoomin    proc
  1066. ;------------------------------
  1067. ; dispaly message
  1068. ;------------------------------
  1069.     mov    esi,offset mzoin    ; display menu items
  1070.     call    dspmenu
  1071.     xor    ax,ax            ; wait no press state
  1072.     call    waitp
  1073.     mov    esi,offset frame    ; frame data address
  1074.     call    dspzx            ; display zoom in x position
  1075.     call    dspzy            ; display zoom in y position
  1076.     call    revfr            ; display frame
  1077. ;-------------------------------
  1078. ; command input
  1079. ;-------------------------------
  1080. zoin20:    call    getpad
  1081.     test    ax,ax
  1082.     jz    zoin20
  1083.     push    ax
  1084.     call    waitv            ; wait VSYNC trigger
  1085.     call    revfr            ; clear frame
  1086.     pop    ax
  1087.     test    ah,P$TRIG1
  1088.     jnz    zoin80            ; decision
  1089.     test    ah,P$TRIG2
  1090.     jnz    main30            ; return to main menu
  1091.     cmp    al,P$RUN
  1092.     je    zoin40            ; magnify
  1093.     cmp    al,P$SEL
  1094.     je    zoin50            ; reduce
  1095.     cmp    al,P$FWD
  1096.     je    zoin32            ; move up
  1097.     cmp    al,P$BACK
  1098.     je    zoin36            ; move down
  1099.     cmp    al,P$LEFT
  1100.     je    zoin38            ; move left
  1101. ;-------------------------------
  1102. ; move frame
  1103. ; in : esi = frame data address
  1104. ;-------------------------------
  1105.     add    word ptr [esi],2    ; move right
  1106.     call    revrl            ; revise right limit
  1107. zoin30:    call    revfr            ; display frame
  1108.     call    dspzx            ; display zoom in x position
  1109.     jmp    zoin20
  1110. ;
  1111. zoin32:    sub    word ptr [esi+2],2    ; move up
  1112.     cmp    word ptr [esi+2],SCRY    ; check upper limit
  1113.     jge    zoin34            ; OK!
  1114.     mov    word ptr [esi+2],SCRY    ; adjust
  1115. zoin34:    call    revfr            ; display frame
  1116.     call    dspzy            ; display zoom in y position
  1117.     jmp    zoin20
  1118. ;
  1119. zoin36:    add    word ptr [esi+2],2    ; move down
  1120.     call    revdl            ; revise down limit
  1121.     jmp    zoin34
  1122. ;
  1123. zoin38:    sub    word ptr [esi],2    ; move left
  1124.     cmp    word ptr [esi],SCRX    ; check left limit
  1125.     jge    zoin30            ; OK!
  1126.     mov    word ptr [esi],SCRX    ; adjust
  1127.     jmp    zoin30
  1128. ;-------------------------------
  1129. ; magnify frame size
  1130. ; in : esi = frame data address
  1131. ;-------------------------------
  1132. zoin40:    add    word ptr [esi+4],2    ; extend width
  1133.     add    word ptr [esi+6],2    ; extend hight
  1134.     dec    word ptr [esi]        ; x position -1
  1135.     dec    word ptr [esi+2]    ; y position -1
  1136.     cmp    word ptr [esi+4],SCRW    ; check width (unite hight)
  1137.     jbe    zoin42            ; OK!
  1138.     mov    word ptr [esi+4],SCRW    ; adjust width
  1139.     mov    word ptr [esi+6],SCRW    ; adjust hight
  1140. ;
  1141. zoin42:    cmp    word ptr [esi+2],SCRY    ; check upper limit
  1142.     jge    zoin44            ; OK!
  1143.     mov    word ptr [esi+2],SCRY    ; adjust y position
  1144. zoin44:    call    revdl            ; revise down limit
  1145.     cmp    word ptr [esi],SCRX    ; check left limit
  1146.     jge    zoin46            ; OK!
  1147.     mov    word ptr [esi],SCRX    ; adjust x position
  1148. zoin46:    call    revrl            ; revise right limit
  1149. zoin48:    call    revfr            ; display frame
  1150.     call    dspzx            ; display zoom in x position
  1151.     call    dspzy            ; display zoom in y position
  1152.     jmp    zoin20
  1153. ;-------------------------------
  1154. ; reduce frame size
  1155. ; in : esi = frame data address
  1156. ;-------------------------------
  1157. zoin50: sub    word ptr [esi+4],2    ; narrow width
  1158.     sub    word ptr [esi+6],2    ; narrow hight
  1159.     inc    word ptr [esi]        ; x position +1
  1160.     inc    word ptr [esi+2]    ; y position +1
  1161.     cmp    word ptr [esi+4],MINFR    ; check frame size
  1162.     jge    zoin48            ; OK!
  1163.     mov    word ptr [esi+4],MINFR    ; adjust frame size
  1164.     mov    word ptr [esi+6],MINFR
  1165.     dec    word ptr [esi]        ; x position -1
  1166.     dec    word ptr [esi+2]    ; y position -1
  1167.     jmp    zoin48
  1168. ;-------------------------------
  1169. ; change region
  1170. ;-------------------------------
  1171. zoin80:    movzx    eax,word ptr [esi+4]    ; frame width
  1172.     mul    reso
  1173.     mov    ecx,SCRW    ; screen width
  1174.     div    ecx        ; calculate new resolution
  1175.     test    eax,eax        ; check effectiveness
  1176.     jz    main30        ; interrupt to menu mode
  1177.     push    eax        ; save new resolution
  1178. ;
  1179.     mov    ax,[esi]    ; frame x position
  1180.     sub    ax,SCRX        ; x pixcel position in screen
  1181.     cwde
  1182.     mul    reso
  1183.     add    posx,eax    ; new x position
  1184. ;
  1185.     mov    ax,[esi+2]    ; frame y position
  1186.     sub    ax,SCRY        ; y pixcel position in screen
  1187.     cwde
  1188.     mul    reso
  1189.     add    posy,eax    ; new y position
  1190. ;
  1191.     pop    eax        ; load new resolution
  1192.     mov    reso,eax    ; set new resolution
  1193. ;
  1194.     call    dspfp        ; display new frame parameter
  1195.     mov    curstat,DS$NONE    ; display start
  1196.     jmp    main10        ; go to display
  1197.  
  1198. ;1111111111111111111111111111111
  1199. ; dspzx : display position x
  1200. ;          in zoom in frame
  1201. ;
  1202. ; in : esi = frame data address
  1203. ; call: putfp
  1204. ; use: all except for esi
  1205. ;
  1206. dspzx    proc
  1207.     mov    ax,[esi]    ; frame x position
  1208.     sub    ax,SCRX        ; x pixcel position in screen
  1209.     cwde
  1210.     mul    reso
  1211.     add    eax,posx    ; new x position
  1212.     mov    edi,LZPOSX
  1213.     push    esi
  1214.     call    putfp
  1215.     pop    esi
  1216.     ret
  1217. dspzx    endp
  1218.  
  1219. ;1111111111111111111111111111111
  1220. ; dspzy : display position y
  1221. ;          in zoom in frame
  1222. ;
  1223. ; in : esi = frame data address
  1224. ; call: putfp
  1225. ; use: all except for esi
  1226. ;
  1227. dspzy    proc
  1228.     mov    ax,[esi+2]    ; frame y position
  1229.     sub    ax,SCRY        ; y pixcel position in screen
  1230.     cwde
  1231.     mul    reso
  1232.     add    eax,posy    ; new y position
  1233.     neg    eax        ; neagative for display
  1234.     mov    edi,LZPOSY
  1235.     push    esi
  1236.     call    putfp
  1237.     pop    esi
  1238.     ret
  1239. dspzy    endp
  1240.  
  1241. ;1111111111111111111111111111111
  1242. ; revdl : revise down limit
  1243. ; in : esi = frame data address
  1244. ;
  1245. revdl    proc
  1246.     mov    ax,SCRY+SCRH        ; down limit + 1
  1247.     sub    ax,[esi+2]        ; effective hight
  1248.     sub    ax,[esi+6]        ; check frame hight
  1249.     jge    revdl9            ; OK!
  1250.     add    [esi+2],ax        ; adjust y position
  1251. revdl9:    ret
  1252. revdl    endp
  1253.  
  1254. ;1111111111111111111111111111111
  1255. ; revrl : revise right limit
  1256. ; in : esi = frame data address
  1257. ;
  1258. revrl    proc
  1259.     mov    ax,SCRX+SCRW        ; right limit + 1
  1260.     sub    ax,[esi]        ; effective width
  1261.     sub    ax,[esi+4]        ; check frame width
  1262.     jge    revrl9            ; OK!
  1263.     add    [esi],ax        ; adjust x position
  1264. revrl9:    ret
  1265. revrl    endp
  1266. zoomin    endp
  1267.  
  1268. ;*******************************
  1269. ; zoomout : zoom out command
  1270. ;*******************************
  1271. zoomout    proc
  1272.     shl    reso,1            ; change resolution
  1273.     imul    eax,reso,SCRW/4
  1274.     sub    posx,eax        ; change x position
  1275.     sub    posy,eax        ; change y position
  1276.     cmp    reso,(4 shl 24)/SCRW    ; check resolution limit
  1277.     jbe    zout10            ; OK!
  1278.     mov    reso,(4 shl 24)/SCRW    ; adjust resolution
  1279. ;
  1280. zout10:    mov    esi,offset posx        ; revise position x
  1281.     call    revpos
  1282.     mov    esi,offset posy        ; revise position y
  1283.     call    revpos
  1284. ;
  1285.     call    dspfp            ; display new frame parameter
  1286.     mov    curstat,DS$NONE        ; display start
  1287.     jmp    main10            ; go to display
  1288.  
  1289. ;1111111111111111111111111111111
  1290. ; revpos : revise position x|y
  1291. ; in : esi = position data address
  1292. ;
  1293. revpos    proc
  1294.     cmp    dword ptr [esi],-2 shl 24    ; check lower limit
  1295.     jge    revp10                ; OK!
  1296.     mov    dword ptr [esi],-2 shl 24    ; adjust position
  1297.     jmp    short revp90
  1298. revp10:    mov    ecx,2 shl 24            ; upper limit
  1299.     sub    ecx,[esi]            ; effective width
  1300.     imul    eax,reso,SCRW            ; screen width
  1301.     sub    ecx,eax
  1302.     jge    revp90                ; OK!
  1303.     add    [esi],ecx            ; adjust position
  1304. revp90:    ret
  1305. revpos    endp
  1306. zoomout    endp
  1307.  
  1308. ;*******************************
  1309. ; whole : return to  whole
  1310. ;*******************************
  1311. whole    proc
  1312.     call    dspis        ; display initial screen
  1313.     jmp    main30        ; go to menu mode
  1314. whole    endp
  1315.  
  1316. ;*******************************
  1317. ; chglim : change limit
  1318. ;*******************************
  1319. chglim    proc
  1320.     mov    ax,limit    ; current limit
  1321.     mov    count1,ax    ; initialize new limit
  1322. ;-------------------------------
  1323. ; display screen
  1324. ;-------------------------------
  1325.     mov    esi,offset mcgl
  1326.     call    dspmenu        ; display menu items
  1327.     mov    ax,limit    ; display current limit
  1328.     mov    edi,LCL1
  1329.     call    putdec
  1330. ;-------------------------------
  1331. ; command input
  1332. ;-------------------------------
  1333.     xor    ax,ax        ; wait no press state
  1334.     call    waitp
  1335. ;
  1336. cgl20:    call    waitv        ; wait VSYNC trigger
  1337.     mov    ax,count1    ; display limit
  1338.     mov    edi,LCL2
  1339.     call    putdec
  1340. cgl22:    call    getpad        ; get pad state
  1341.     cmp    al,P$FWD
  1342.     je    cgl40        ; limit up
  1343.     cmp    al,P$BACK
  1344.     je    cgl50        ; limit down
  1345.     cmp    al,P$RUN
  1346.     je    cgl70        ; automatically limit additon
  1347.     cmp    al,P$SEL
  1348.     je    cgl60        ; automatically limit up
  1349.     test    ah,P$TRIG2
  1350.     jnz    main30        ; cancel to return main menu
  1351.     test    ah,P$TRIG1
  1352.     jz    cgl22        ; invalid
  1353. ;-------------------------------
  1354. ; decision upper limit
  1355. ;-------------------------------
  1356.     mov    ax,count1    ; new limit number
  1357.     mov    limit,ax    ; set mew limit
  1358.     mov    edi,LLIMIT    ; display new limit
  1359.     call    putdec
  1360.     mov    curstat,DS$NONE    ; request redisplay
  1361.     jmp    main10        ; go to display
  1362. ;-------------------------------
  1363. ; limit up
  1364. ;-------------------------------
  1365. cgl40:    add    count1,10    ; limit up
  1366.     jnc    cgl20
  1367.     sub    count1,10    ; recover
  1368.     jmp    cgl22
  1369. ;-------------------------------
  1370. ; limit down
  1371. ;-------------------------------
  1372. cgl50:    sub    count1,10    ; limit down
  1373.     ja    cgl20
  1374.     add    count1,10    ; recover
  1375.     jmp    cgl22
  1376. ;-------------------------------
  1377. ; automatically limit up
  1378. ;-------------------------------
  1379. cgl60:    cmp    bufsiz,SCRW*SCRW*8    ; check memorey
  1380.     jb    cgl68        ; can't execute
  1381. ;
  1382.     mov    esi,offset mautup    ; auto up menu index
  1383.     call    dspmenu        ; display menu items
  1384.     call    calup        ; calculate up method
  1385.     jnc    cgl68        ; calculate up end
  1386.     test    ah,P$TRIG1
  1387.     jz    cgl68        ; quit end
  1388. ;
  1389.     mov    ax,hbnum    ; next limit number
  1390.     dec    ax        ; new limit number
  1391.     mov    limit,ax    ; set new limit
  1392.     mov    edi,LLIMIT    ; display new limit
  1393.     call    putdec
  1394. cgl68:    jmp    main20        ; go to scroll mode
  1395. ;-------------------------------
  1396. ; automatically additon
  1397. ;-------------------------------
  1398. cgl70:    call    dspmain        ; display main mandelbrot figure
  1399.     jc    cgl90        ; interrupted
  1400. ;
  1401.     mov    esi,offset mautad    ; auto additon menu index
  1402.     call    dspmenu
  1403.     push    limit        ; save current limit
  1404. cgl76:    shl    limit,1        ; double limit
  1405.     jc    cgl78        ; limit over
  1406.     mov    ax,limit    ; display limit
  1407.     mov    edi,LAUP
  1408.     call    putdec
  1409.     call    dspadd        ; display additive
  1410.     jnc    cgl76        ; not intrrupted
  1411. ;
  1412.     test    ah,P$TRIG1    ; press A button ?
  1413.     jz    cgl78        ; no then end without changing limit
  1414.     mov    ax,limit    ; interrupted limit
  1415.     shr    ax,1        ; new limit
  1416.     mov    [esp],ax    ; set new limit on stack
  1417.     mov    edi,LLIMIT    ; display new limit
  1418.     call    putdec
  1419. cgl78:    pop    limit        ; set limit
  1420. ;
  1421. cgl90:    jmp    main20        ; go to scroll mode
  1422. chglim    endp
  1423.  
  1424. ;*******************************
  1425. ; load : load data
  1426. ;*******************************
  1427. load    proc
  1428. ;-------------------------------
  1429. ; file select and open
  1430. ;-------------------------------
  1431.     mov    exts,EXTALL    ; set extension
  1432. load10:    call    open        ; file open
  1433.     jc    main30        ; quit to menu mode
  1434. ;-------------------------------
  1435. ; read location data
  1436. ; in : ax = file handle
  1437. ;-------------------------------
  1438.     mov    bx,ax            ; file handel
  1439.     mov    ecx,size locdat        ; location data size
  1440.     mov    edx,offset work1    ; buffer pointer
  1441.     mov    ah,3Fh            ; read file
  1442.     int    21h
  1443.     jnc    load30            ; complete
  1444. ;
  1445. load20:    mov    ah,3Eh            ; file close
  1446.     int    21h
  1447.     jmp    load10            ; repeat file open
  1448. ;-------------------------------
  1449. ; check location data & set
  1450. ; in : edx = data address
  1451. ;-------------------------------
  1452. load30:    mov    eax,[edx].locdatr    ; resolution
  1453.     test    eax,eax
  1454.     jz    load20            ; too small
  1455.     cmp    eax,(4 shl 24)/SCRW    ; check range
  1456.     ja    load20            ; too big
  1457.     mov    ecx,-2 shl 24        ; location low limit
  1458.     mov    esi,[edx].locdatx    ; position x
  1459.     cmp    esi,ecx            ; check x low limit
  1460.     jl    load20            ; too small
  1461.     mov    edi,[edx].locdaty    ; position y
  1462.     cmp    edi,ecx            ; check y low limit
  1463.     jl    load20            ; too small
  1464.     push    eax
  1465.     imul    eax,SCRW        ; screen width/hight
  1466.     neg    ecx            ; location hight limit
  1467.     sub    ecx,eax
  1468.     pop    eax
  1469.     cmp    esi,ecx            ; check x high position
  1470.     jg    load20            ; too big
  1471.     cmp    edi,ecx            ; check y high position
  1472.     jg    load20            ; too big
  1473. ;
  1474.     mov    posx,esi        ; set position x
  1475.     mov    posy,edi        ; set position y
  1476.     mov    reso,eax        ; set resolution
  1477.     mov    ax,[edx].locdatl    ; limit
  1478.     mov    limit,ax        ; set limit
  1479. ;-------------------------------
  1480. ; load color data
  1481. ; in : bx = file handle
  1482. ;-------------------------------
  1483.     call    savpal            ; backup color data
  1484.     mov    edx,offset palbuf
  1485.     mov    ecx,(1+USRCN)*3        ; color data byte size
  1486.     mov    ah,3Fh            ; read file
  1487.     int    21h
  1488. ;-------------------------------
  1489. ; file close & ending
  1490. ; in : bx = file handle
  1491. ;-------------------------------
  1492.     mov    ah,3Eh            ; file close
  1493.     int    21h
  1494. ;
  1495.     call    dspfp            ; display frame parameter
  1496.     mov    ax,limit        ; limit
  1497.     mov    edi,LLIMIT        ; display limit
  1498.     call    putdec
  1499.     call    setdp            ; set display pallet
  1500. ;
  1501.     mov    curstat,DS$NONE        ; request full display
  1502.     jmp    main10            ; go to display
  1503. load    endp
  1504.  
  1505. ;*******************************
  1506. ; open : file open
  1507. ;     with file selector
  1508. ;
  1509. ; in : exts = extension
  1510. ;      buffer = file name buffer pointer
  1511. ; out: cf = set for quit
  1512. ;      ax = file handel
  1513. ; call: dspmenu,waitp,chgsc,getpad
  1514. ;       waitv,makpath
  1515. ; use: all register
  1516. ;      work1,count1,count2,hbnum
  1517. ;
  1518. SCRSTEP    equ    3    ; scroll step
  1519. MAXFIN    equ    8    ; maximum file item number
  1520. open    proc
  1521. ;-------------------------------
  1522. ; intialize
  1523. ;-------------------------------
  1524.     mov    esi,offset mload
  1525.     call    dspmenu        ; display menu items
  1526.     xor    ax,ax
  1527.     mov    count1,ax    ; file number of top item
  1528.     mov    count2,ax    ; item number
  1529.     mov    hbnum,ax    ; file number of current DTA
  1530. ;
  1531.     xor    ax,ax        ; item number
  1532.     call    dspfn        ; display file name
  1533.     jc    open90        ; quit end
  1534.     mov    ax,1
  1535. open10:    push    ax
  1536.     call    dspfn        ; display file name
  1537.     pop    ax
  1538.     jc    open18        ; no exist
  1539.     inc    ax
  1540.     cmp    ax,MAXFIN-1
  1541.     jbe    open10
  1542. ;
  1543. open18:    xor    ax,ax        ; wait no press state
  1544.     call    waitp
  1545.     mov    repcnt,INIREP    ; clear pad input counter
  1546. ;-------------------------------
  1547. ; intesify current item
  1548. ;-------------------------------
  1549. open20:    movzx    edi,count2
  1550.     imul    edi,18*VRAMW
  1551.     add    edi,(MENUY+35)*VRAMW+MENUX+28
  1552.     mov    bx,8*8+1    ; string witdh
  1553.     mov    ax,C$DARK+C$INT*256
  1554.     call    chgsc        ; intensify string
  1555. ;-------------------------------
  1556. ; input pad
  1557. ;-------------------------------
  1558. open40:    call    getpad
  1559.     test    ax,ax        ; press key ?
  1560.     jz    open40        ; no press state
  1561.     test    ah,P$TRIG1    ; A button
  1562.     jnz    open80        ; go to open
  1563.     test    ah,P$TRIG2    ; B button
  1564.     jnz    open90        ; quit
  1565.     cmp    al,P$BACK
  1566.     je    open70        ; move down
  1567.     cmp    al,P$FWD
  1568.     je    open50        ; move up
  1569. ;
  1570.     mov    repcnt,INIREP    ; clear pad input counter
  1571.     jmp    open40
  1572. ;-------------------------------
  1573. ; cursor move up
  1574. ; in : edi = string box address
  1575. ;-------------------------------
  1576. open50:    mov    ax,count2    ; current item number
  1577.     dec    ax        ; move up
  1578.     jns    open60        ; executable
  1579.     mov    ax,count1    ; current top file number
  1580.     dec    ax
  1581.     js    open40        ; can't scroll down
  1582.     mov    count1,ax    ; new top file number
  1583. ;
  1584.     mov    eax,C$PANEL+(C$PANEL shl 8)+(C$PANEL shl 16)+(C$PANEL shl 24)
  1585.     mov    bx,18/SCRSTEP
  1586. open52:    mov    esi,(MENUY+32+18*MAXFIN-SCRSTEP)*VRAMW+MENUX+28
  1587.     mov    edi,(MENUY+32+18*MAXFIN)*VRAMW+MENUX+28
  1588.     mov    dx,18*MAXFIN-2-SCRSTEP
  1589.     call    waitv        ; wait VSYNC trigger
  1590. open54:    mov    ecx,8*8/4
  1591.     rep    movs    dword ptr [edi],es:[esi]
  1592.     sub    esi,VRAMW+8*8
  1593.     sub    edi,VRAMW+8*8
  1594.     dec    dx
  1595.     jnz    open54
  1596.     mov    dx,SCRSTEP
  1597. open56:    mov    ecx,8*8/4
  1598.     rep    stosd
  1599.     sub    edi,VRAMW+8*8
  1600.     dec    dx
  1601.     jnz    open56
  1602.     dec    bx
  1603.     jnz    open52
  1604. ;
  1605.     xor    ax,ax        ; top item
  1606.     call    dspfn        ; display file name
  1607.     mov    edi,(MENUY+35+18)*VRAMW+MENUX+28    ; next item address
  1608.     jmp    short open62
  1609. ;-------------------------------
  1610. ; check repeatable & set new item
  1611. ; in : edi = string box address
  1612. ;      ax = new item number
  1613. ;-------------------------------
  1614. open60:    call    repable        ; repeatalbe ?
  1615.     jc    open40        ; invalid
  1616.     mov    count2,ax    ; renew item number
  1617. open62:    mov    bx,8*8+1    ; string width
  1618.     mov    ax,C$INT+C$DARK*256
  1619.     call    chgsc        ; weaken string
  1620.     jmp    open20        ; go to display cursor
  1621. ;-------------------------------
  1622. ; cursor move down
  1623. ; in : edi = string box address
  1624. ;-------------------------------
  1625. open70:    mov    ax,count2    ; current item number
  1626.     add    ax,count1    ; current file number
  1627.     inc    ax        ; next file number
  1628.     push    edi
  1629.     call    getfp        ; get file name string pointer
  1630.     pop    edi
  1631.     jc    open40        ; no exist
  1632. ;
  1633.     mov    ax,count2    ; current item number
  1634.     inc    ax        ; next item number
  1635.     cmp    ax,MAXFIN-1    ; check down limit
  1636.     jbe    open60        ; OK!
  1637. ;
  1638.     mov    eax,C$PANEL+(C$PANEL shl 8)+(C$PANEL shl 16)+(C$PANEL shl 24)
  1639.     mov    bx,18/SCRSTEP
  1640. open72:    mov    esi,(MENUY+35+SCRSTEP)*VRAMW+MENUX+28
  1641.     mov    edi,(MENUY+35)*VRAMW+MENUX+28
  1642.     mov    dx,18*MAXFIN-2-SCRSTEP
  1643.     call    waitv        ; wait VSYNC trigger
  1644. open74:    mov    ecx,8*8/4
  1645.     rep    movs    dword ptr [edi],es:[esi]
  1646.     add    esi,VRAMW-8*8
  1647.     add    edi,VRAMW-8*8
  1648.     dec    dx
  1649.     jnz    open74
  1650.     mov    dx,SCRSTEP
  1651. open76:    mov    ecx,8*8/4
  1652.     rep    stosd
  1653.     add    edi,VRAMW-8*8
  1654.     dec    dx
  1655.     jnz    open76
  1656.     dec    bx
  1657.     jnz    open72
  1658. ;
  1659.     inc    count1        ; new top file number
  1660.     mov    ax,MAXFIN-1    ; bottom item
  1661.     call    dspfn        ; display file name
  1662.     mov    edi,(MENUY+35+18*(MAXFIN-2))*VRAMW+MENUX+28    ; weaken item
  1663.     jmp    open62
  1664. ;-------------------------------
  1665. ; file open
  1666. ;-------------------------------
  1667. open80:    mov    ax,count1    ; top item file number
  1668.     add    ax,count2    ; destination file number
  1669.     call    getfp        ; get file name string pointer
  1670.     jc    open90        ; don't exist
  1671.     mov    eax,exts    ; extension string
  1672.     call    makpath        ; make pathlist
  1673.     mov    edx,offset pathbuf+1
  1674.     mov    ax,3D00h    ; read open
  1675.     int    21h
  1676.     ret
  1677. open90:    stc        ; quit end
  1678.     ret
  1679.  
  1680. ;*******************************
  1681. ; getfp : get file name stinrg pointer
  1682. ;    with 6 byte header
  1683. ;
  1684. ; in : ax = file number
  1685. ;      hbnum = current readin number
  1686. ; out: esi = file name pointer
  1687. ; err: cf = set by no exist
  1688. ;
  1689. getfp    proc
  1690.     push    es
  1691.     mov    dx,0004h    ; PSP selector
  1692.     mov    es,dx
  1693.     mov    esi,buffer    ; saving buffer pointer
  1694.     cmp    ax,hbnum    ; check read in
  1695.     jb    getfp7        ; red
  1696.     mov    bx,ax        ; save destination file number
  1697. ;-------------------------------
  1698. ; read file names in buffer
  1699. ; in : bx = destination file number
  1700. ;      esi = buffer pointer
  1701. ;-------------------------------
  1702.     mov    ax,6+13
  1703.     mul    hbnum
  1704.     cwde
  1705.     add    esi,eax        ; saving start address
  1706.     test    ax,ax        ; first read ?
  1707.     jz    getfp4        ; yes
  1708. ;
  1709. getfp1:    mov    ah,4Fh        ; search next file
  1710.     int    21h
  1711.     jc    getfp9        ; don't find
  1712. ;
  1713. getfp2:    mov    edi,80h+1Eh    ; file name offset in DTA buffer
  1714.     mov    word ptr [esi+4],-5    ; clear file name length
  1715.     mov    ecx,esi
  1716.     add    ecx,6        ; skip header bytes
  1717. getfp3:    mov    al,es:[edi]
  1718.     mov    byte ptr [ecx],al
  1719.     inc    word ptr [esi+4]    ; count up file name length
  1720.     inc    edi        ; proceed addresses
  1721.     inc    ecx
  1722.     test    al,al        ; check string end
  1723.     jnz    getfp3        ; go to read next charactor
  1724.     inc    hbnum        ; renew readin number
  1725.     cmp    bx,hbnum    ; check file number
  1726.     jb    getfp8        ; found
  1727.     add    esi,6+13    ; next file name saving address
  1728.     jmp    getfp1
  1729. ;
  1730. getfp4:    mov    edx,offset pathbuf+1    ; search pathlist pointer
  1731.     movzx    ecx,byte ptr [edx-1]    ; directory list length
  1732.     mov    byte ptr [edx+ecx],'*'    ; set wild card
  1733.     mov    eax,exts        ; extension string
  1734.     mov    [edx+ecx+1],eax        ; set extension(ex. ".MDL")
  1735.     mov    byte ptr [edx+ecx+5],0    ; null terminate
  1736.     xor    cx,cx        ; normal attribute
  1737.     mov    ah,4Eh        ; search first file
  1738.     int    21h
  1739.     jc    getfp9        ; don't find
  1740.     jmp    getfp2
  1741. ;-------------------------------
  1742. ; return file string pointer
  1743. ; in : ax = file number
  1744. ;      esi = buffer pointer
  1745. ;-------------------------------
  1746. getfp7:    imul    ax,6+13
  1747.     cwde
  1748.     add    esi,eax
  1749. getfp8:    clc
  1750. getfp9:    pop    es
  1751.     ret
  1752. getfp    endp
  1753.  
  1754. ;*******************************
  1755. ; dspfn : display file name
  1756. ;
  1757. ; in : ax = item number
  1758. ;      count1 = top file number
  1759. ;      fs = TOWNS BIOS selector
  1760. ; err: cf = set by no exist
  1761. ; call: getfp
  1762. ;
  1763. dspfn    proc
  1764.     push    ax
  1765.     add    ax,count1    ; distination file number
  1766.     call    getfp        ; get file name pointer
  1767.     pop    ax
  1768.     jc    dspfn9        ; no exist
  1769. ;
  1770.     mov    word ptr [esi],MENUX+28    ; set x position
  1771.     imul    ax,18
  1772.     add    ax,MENUY+50
  1773.     mov    [esi+2],ax    ; set y position
  1774.     mov    ah,60h        ; display string
  1775.     mov    edi,offset egbwork
  1776.     call    pword ptr fs:[20h]
  1777.     clc
  1778. dspfn9:    ret
  1779. dspfn    endp
  1780.  
  1781. ;*******************************
  1782. ; makpath : make pathlist
  1783. ;
  1784. ; in : esi = file name string
  1785. ;          4(2) byte length
  1786. ;          6(n) file name
  1787. ;      eax = extension (.MDL/.MDC)
  1788. ;      pathbuf = directory list
  1789. ; out: pathbuf = pathlist buffer
  1790. ;          1(n) pathlist (ASCIZ)
  1791. ; err: cf = set by invalid file name
  1792. ; use: ecx,esi,edi
  1793. ;
  1794. makpath    proc
  1795.     push    es
  1796.     mov    cx,ds            ; set es selector
  1797.     mov    es,cx
  1798.     mov    edi,offset pathbuf    ; pathlist buffer pointer
  1799.     movzx    ecx,byte ptr [edi]    ; directory list length
  1800.     inc    ecx            ; add byte of length
  1801.     add    edi,ecx            ; directory tail address
  1802.     movzx    ecx,word ptr [esi+4]    ; file name byte length
  1803.     cmp    ecx,1            ; check length
  1804.     jc    makpa9            ; invalid
  1805.     add    esi,6            ; file name start address & clear carry
  1806.     rep    movsb            ; copy file name
  1807.     mov    [edi],eax        ; set extension (ex. ".MDL")
  1808.     mov    byte ptr [edi+4],0    ; null terminate
  1809. makpa9:    pop    es
  1810.     ret
  1811. makpath    endp
  1812. open    endp
  1813.  
  1814. ;*******************************
  1815. ; save : save data
  1816. ;*******************************
  1817. save    proc
  1818. ;-------------------------------
  1819. ; input file name and create
  1820. ;-------------------------------
  1821. save10:    mov    eax,EXTALL    ; extension
  1822.     call    create        ; file create
  1823.     jc    save90        ; quit
  1824. ;-------------------------------
  1825. ; write data
  1826. ; in : ax = file handle
  1827. ;-------------------------------
  1828.     mov    edx,offset posx    ; data pointer
  1829.     mov    ecx,size locdat    ; location data byte size
  1830.     mov    bx,ax        ; file handle
  1831.     mov    ah,40h        ; write
  1832.     int    21h
  1833.     jc    save50
  1834.     mov    edx,offset palbuf
  1835.     mov    ecx,(1+USRCN)*3    ; color data byte size
  1836.     mov    ah,40h        ; write
  1837.     int    21h
  1838. ;-------------------------------
  1839. ; handle close
  1840. ; in : bx = file handle
  1841. ;      cf = error flag
  1842. ;-------------------------------
  1843. save50:    pushf
  1844.     mov    ah,3Eh        ; file close
  1845.     int    21h
  1846.     popf
  1847.     jc    save10        ; repeat input
  1848. save90:    jmp    main30        ; go to menu mode
  1849. save    endp
  1850.  
  1851. ;*******************************
  1852. ; create : create file
  1853. ;
  1854. ; in : eax = extension
  1855. ;      pathbuf = directory path
  1856. ; out: cf = set for quit
  1857. ;      ax = file handel
  1858. ; call: dspmenu,getstr,makpath
  1859. ; use: all reg & work1
  1860. ;
  1861. LOCFI    equ    (MENUX+(MENUW-8*8)/2)+((MENUY+80) shl 16)
  1862. create    proc
  1863.     push    eax        ; save extension
  1864. ;-------------------------------
  1865. ; display screen
  1866. ;-------------------------------
  1867. crte10:    mov    esi,offset msave
  1868.     call    dspmenu        ; display menu items
  1869. ;-------------------------------
  1870. ; get file name
  1871. ;-------------------------------
  1872.     mov    esi,offset work1
  1873.     mov    dword ptr [esi],LOCFI    ; location of file input
  1874.     mov    cx,8        ; maximum length
  1875.     call    getstr        ; get string from keybord
  1876. ;-------------------------------
  1877. ; make pathlist
  1878. ; in : esi = string buffer base
  1879. ;-------------------------------
  1880.     mov    eax,[esp]    ; extension
  1881.     call    makpath        ; make pathlist
  1882.     jc    crte99        ; quit
  1883. ;-------------------------------
  1884. ; file create
  1885. ;-------------------------------
  1886.     mov    edx,offset pathbuf+1
  1887.     mov    ah,3Ch        ; file create
  1888.     xor    cx,cx        ; common attribute
  1889.     int    21h
  1890.     jc    crte10        ; go to repeat
  1891. ;
  1892. crte99:    pop    ecx        ; abandon
  1893.     ret
  1894. create    endp
  1895.  
  1896. ;*******************************
  1897. ; chgcol : change color
  1898. ;*******************************
  1899. chgcol    proc
  1900.     mov    spflg,FALSE    ; save pallet flag off
  1901. chgco1:    mov    esi,offset mcgc
  1902.     call    dspmenu        ; display menu items
  1903.     mov    bx,offset sicol    ; selector data address
  1904.     call    select        ; select item
  1905.     jc    main30        ; escape to main menu mode
  1906.     shl    ax,2        ; make offset
  1907.     cwde
  1908.     jmp    cmdtbl2[eax]    ; jump destination procedure
  1909. chgcol    endp
  1910.  
  1911. ;*******************************
  1912. ; indcol : change color individually
  1913. ;*******************************
  1914. indcol    proc
  1915. ;-------------------------------
  1916. ; initailize
  1917. ;-------------------------------
  1918.     mov    numwid,3    ; set display width of integer
  1919.     mov    cura,SCRX+SCRW/2    ; cross cursor x position
  1920.     mov    curb,SCRY+SCRH/2    ; cross cursor y position
  1921. ;
  1922. indc10:    mov    esi,offset mindc
  1923.     call    dspmenu        ; display menu items
  1924.     mov    repcnt,INIREP    ; intialize repeat counter
  1925.     xor    ax,ax        ; wait no press state
  1926.     call    waitp
  1927. ;-------------------------------
  1928. ; display current color data
  1929. ;-------------------------------
  1930. indc20:    call    dsppbs        ; display panel & bars
  1931. ;-------------------------------
  1932. ; command input
  1933. ;-------------------------------
  1934. indc40:    call    getpad        ; get pad state
  1935.     cmp    al,P$LEFT
  1936.     je    indc50        ; pallet code down
  1937.     cmp    al,P$RIGHT
  1938.     je    indc60        ; pallet code up
  1939.     mov    repcnt,INIREP    ; intialize repeat counter
  1940.     cmp    al,P$SEL
  1941.     je    extpix        ; go to extract pallet number from poxcel
  1942.     test    ah,P$TRIG1
  1943.     jnz    coledit        ; go to edit mode
  1944.     test    ah,P$TRIG2
  1945.     jz    indc40        ; invalid
  1946. ;
  1947. indc90:    mov    numwid,5    ; restore width of integer
  1948.     jmp    chgco1        ; go to change color menu mode
  1949. ;-------------------------------
  1950. ; color number down
  1951. ;-------------------------------
  1952. indc50:    call    repable        ; repeatable ?
  1953.     jc    indc40        ; invalid
  1954.     movzx    ax,colnum    ; current color number
  1955.     sub    ax,1        ; number down
  1956.     jb    indc40        ; invalid
  1957.     mov    colnum,al    ; set new number
  1958.     jmp    indc20        ; to display
  1959. ;-------------------------------
  1960. ; color number up
  1961. ;-------------------------------
  1962. indc60:    call    repable        ; repeatable ?
  1963.     jc    indc40        ; invalid
  1964.     movzx    ax,colnum    ; current color number
  1965.     inc    ax        ; number up
  1966.     cmp    ax,USRCN    ; check
  1967.     ja    indc40        ; invalid
  1968.     mov    colnum,al    ; set new number
  1969.     jmp    indc20        ; go to dispaly
  1970. indcol    endp
  1971.  
  1972. ;*******************************
  1973. ; dsppbs : display panel & bars
  1974. ; copy bpal,rpal,gpal from colbuf
  1975. ;
  1976. ; in : colnum = color number
  1977. ;      palbuf = pallet buffer
  1978. ; out: bpal,rpal,gpal
  1979. ; call: getpal,dspcp,dspbar
  1980. ; use: all
  1981. ;
  1982. dsppbs    proc
  1983.     call    getpal        ; get pallet data
  1984.     call    dspcp        ; display color panel
  1985.     xor    al,al        ; blue
  1986.     call    dspbar        ; display bar
  1987.     mov    al,1        ; red
  1988.     call    dspbar        ; display bar
  1989.     mov    al,2        ; green
  1990.     call    dspbar        ; display bar
  1991.     ret
  1992. dsppbs    endp
  1993.  
  1994. ;*******************************
  1995. ; getpal : get pallet data
  1996. ;   from palbuf to palpkt
  1997. ;
  1998. ; in : colnum = color number
  1999. ;      palbuf = pallet buffer
  2000. ; out: bpal,rpal,gpal
  2001. ; use: eax,esi
  2002. ;
  2003. getpal    proc
  2004.     movzx    esi,colnum
  2005.     imul    esi,3        ; pallet data offset
  2006.     mov    eax,dword ptr ss:palbuf[esi]    ; level data + 1
  2007.     mov    dword ptr bpal,eax    ; set level data
  2008.     ret
  2009. getpal    endp
  2010.  
  2011. ;*******************************
  2012. ; dspcp : display color panel
  2013. ;    with color code number
  2014. ;
  2015. ; in : colnum = color number
  2016. ; call: putdec
  2017. ;
  2018. LINDCC    equ    MENUX+(MENUW-24)/2+(MENUY+44)*VRAMW    ; color code
  2019. dspcp    proc
  2020.     movzx    ax,colnum    ; dispaly current color number
  2021.     mov    edi,LINDCC
  2022.     call    putdec
  2023. ;
  2024.     mov    edi,(MENUY+47)*VRAMW+MENUX+(MENUW-74)/2
  2025.     mov    bx,16        ; set hight counter
  2026.     mov    al,colnum    ; color number
  2027.     mov    ah,al        ; extend AL to AX
  2028. dscp10:    mov    ecx,74/2    ; set width counter
  2029.     rep    stosw
  2030.     add    edi,VRAMW-74
  2031.     dec    bx
  2032.     jnz    dscp10
  2033.     ret
  2034. dspcp    endp
  2035.  
  2036. ;*******************************
  2037. ; dspbar : display level bar
  2038. ;
  2039. ; in : al = RGB species
  2040. ;           B=0,R=1,G=2
  2041. ;      bpal,rpal,gpal
  2042. ; call: putdec
  2043. ;
  2044. LINDCB    equ    MENUX+(MENUW-70)/2+72+(MENUY+92)*VRAMW    ; blue level number
  2045. dspbar    proc
  2046.     movzx    esi,al        ; RGB offset
  2047.     add    esi,offset bpal    ; destination address
  2048.     movzx    edi,al
  2049.     imul    edi,16*VRAMW
  2050.     add    edi,LINDCB    ; destination display VRAM address
  2051.     movzx    ax,byte ptr [esi]    ; destination level
  2052.     push    edi
  2053.     push    ax
  2054.     call    putdec
  2055.     pop    dx        ; destination level
  2056.     pop    edi
  2057.     add    edi,-14*VRAMW-72+3
  2058. ;-------------------------------
  2059. ; draw color level bar
  2060. ; in : edi = bar address
  2061. ;      dl = color level
  2062. ;-------------------------------
  2063.     xor    dh,dh
  2064.     add    dx,11b        ; round
  2065.     shr    dx,2
  2066.     mov    dh,64        ; total width
  2067.     sub    dh,dl        ; top blank width
  2068.     mov    bh,12        ; set hight counter
  2069. dsbar1:    movzx    ecx,dl
  2070.     mov    al,C$INT
  2071.     rep    stosb
  2072.     movzx    ecx,dh
  2073.     mov    al,C$PANEL
  2074.     rep    stosb
  2075.     add    edi,VRAMW-64    ; next line
  2076.     dec    bh
  2077.     jnz    dsbar1
  2078.     ret
  2079. dspbar    endp
  2080.  
  2081. ;*******************************
  2082. ; coledit : color edit
  2083. ;*******************************
  2084. coledit    proc
  2085. ;-------------------------------
  2086. ; initailize
  2087. ;-------------------------------
  2088.     mov    esi,offset mced
  2089.     call    dspmenu        ; display menu items
  2090.     call    dsppbs        ; display color panel & bars
  2091.     xor    ax,ax        ; wait no press state
  2092.     call    waitp
  2093.     mov    al,colnum
  2094.     mov    palnum,al
  2095.     mov    al,C$INT    ; string color
  2096.     call    dspRGB        ; display destination RGB string
  2097.     cmp    spflg,TRUE    ; check save pallet flag
  2098.     je    ced10
  2099.     call    savpal        ; save all pallets
  2100.     mov    spflg,TRUE
  2101. ced10:    mov    repcnt,INIREP    ; intialize repeat counter
  2102. ;-------------------------------
  2103. ; command input
  2104. ;-------------------------------
  2105. ced40:    call    getpad        ; get pad state
  2106.     cmp    al,P$SEL
  2107.     je    ced60        ; RGB rotate
  2108.     mov    repcnt,INIREP    ; intialize repeat counter
  2109.     cmp    al,P$RIGHT
  2110.     je    ced50        ; level up
  2111.     cmp    al,P$LEFT
  2112.     je    ced55        ; level down
  2113.     test    ah,P$TRIG2
  2114.     jnz    ced80        ; cancel
  2115.     test    ah,P$TRIG1
  2116.     jz    ced40        ; invalid
  2117. ;
  2118.     movzx    edi,colnum
  2119.     imul    edi,3        ; destination color offset
  2120.     mov    ax,word ptr bpal        ; new pallet levels
  2121.     mov    word ptr ss:palbuf[edi],ax    ; save new color data
  2122.     mov    al,gpal
  2123.     mov    ss:palbuf[edi+2],al
  2124.     jmp    indc10        ; return to color select mode
  2125. ;-------------------------------
  2126. ; color level up
  2127. ;-------------------------------
  2128. ced50:    call    repable        ; repeatable ?
  2129.     jc    ced40        ; invalid
  2130.     movzx    esi,currgb    ; current RGB
  2131.     add    esi,offset bpal    ; destination RGB parameter address
  2132.     inc    byte ptr [esi]    ; increment level
  2133.     jnz    ced52        ; OK!
  2134.     mov    byte ptr [esi],255    ; to maximum value
  2135. ced52:    mov    esi,offset palpkt
  2136.     call    setpal        ; set pallet register
  2137.     mov    al,currgb    ; current RGB
  2138.     call    dspbar        ; display bar
  2139.     jmp    ced40
  2140. ;-------------------------------
  2141. ; color level down
  2142. ;-------------------------------
  2143. ced55:    call    repable        ; repeatable ?
  2144.     jc    ced40        ; invalid
  2145.     movzx    esi,currgb    ; current RGB
  2146.     add    esi,offset bpal    ; destination RGB parameter address
  2147.     sub    byte ptr [esi],1    ; decriment level
  2148.     jnc    ced52        ; OK!
  2149.     inc    byte ptr [esi]    ; to minimum value = 0
  2150.     jmp    ced40
  2151. ;-------------------------------
  2152. ; distination RGB rotate
  2153. ;-------------------------------
  2154. ced60:    call    repable        ; repeatable ?
  2155.     jc    ced40        ; invalid
  2156.     mov    al,C$DARK    ; intensity off
  2157.     call    dspRGB
  2158.     inc    currgb        ; change current RGB species
  2159.     cmp    currgb,2
  2160.     jbe    ced62        ; change OK!
  2161.     mov    currgb,0    ; round
  2162. ced62:    mov    al,C$INT    ; intensity on
  2163.     call    dspRGB
  2164.     jmp    ced40        ; to get next command
  2165. ;-------------------------------
  2166. ; cancel
  2167. ;-------------------------------
  2168. ced80:    call    getpal        ; set pallet data from palbuf to palpkt
  2169.     call    waitv        ; wait VSYNC trigger
  2170.     mov    esi,offset palpkt
  2171.     call    setpal        ; set pallet register
  2172.     jmp    indc10        ; return to color select mode
  2173.  
  2174. ;*******************************
  2175. ; dspRGB : display RGB string
  2176. ;
  2177. ; in : currgb = current RGB species
  2178. ;      al = string color code
  2179. ; call: color
  2180. ;
  2181. dspRGB    proc
  2182.     call    color        ; set string color
  2183.     mov    esi,offset strRGB
  2184.     mov    al,strRGBL    ; string data length
  2185.     mul    currgb        ; current RGB string offset
  2186.     cwde
  2187.     add    esi,eax        ; current RGB string address
  2188.     mov    ah,60h        ; display string
  2189.     call    pword ptr fs:[20h]
  2190.     ret
  2191. dspRGB    endp
  2192. coledit    endp
  2193.  
  2194. ;*******************************
  2195. ; savpal : save pallets
  2196. ;   backup pallets destroy
  2197. ;
  2198. ; in : palbuf = current pallets
  2199. ;      palbak = saving area
  2200. ; use: ax,ecx,esi,edi
  2201. ;
  2202. savpal    proc
  2203.     mov    esi,offset palbuf
  2204.     mov    edi,offset palbak
  2205.     mov    ecx,USRCN+1
  2206. savpa1:    lodsw
  2207.     mov    [edi],ax
  2208.     lodsb
  2209.     mov    [edi+2],al
  2210.     add    edi,3
  2211.     loop    savpa1
  2212.     ret
  2213. savpal    endp
  2214.  
  2215. ;*******************************
  2216. ; extpix : extact pallet number
  2217. ;        from pixcel
  2218. ;*******************************
  2219. extpix    proc
  2220. ;-------------------------------
  2221. ; initialize
  2222. ;-------------------------------
  2223.     mov    esi,offset mexp
  2224.     call    dspmenu        ; display menu items
  2225.     xor    ax,ax        ; wait no press state
  2226.     call    waitp
  2227.     mov    al,C$PANEL
  2228.     xchg    al,colnum    ; initialize number except display color
  2229.     mov    palnum,al    ; save color number
  2230. ;-------------------------------
  2231. ; read pixcel & display
  2232. ;-------------------------------
  2233. expi10:    imul    esi,curb,VRAMW
  2234.     add    esi,cura
  2235.     mov    al,es:[esi]    ; destination pixcel data
  2236.     cmp    al,colnum    ; check same color
  2237.     je    expi48        ; same to skip draw
  2238.     mov    colnum,al    ; save pallet number
  2239.     call    dspcros        ; display cross cursor
  2240.     call    dsppbs        ; display panel & bars
  2241. ;-------------------------------
  2242. ; command input
  2243. ;-------------------------------
  2244. expi40:    call    getpad        ; get pad state
  2245.     test    ax,ax
  2246.     jz    expi40        ; no press
  2247.     call    waitv        ; wait VSYNC
  2248.     call    dspcros        ; erase cross cursor
  2249. ;
  2250.     cmp    al,P$LEFT
  2251.     je    expi50        ; left move
  2252.     cmp    al,P$RIGHT
  2253.     je    expi55        ; right move
  2254.     cmp    al,P$FWD
  2255.     je    expi60        ; up move
  2256.     cmp    al,P$BACK
  2257.     je    expi65        ; down move
  2258.     test    ah,P$TRIG1
  2259.     jnz    indc10        ; go to color number select mode
  2260.     test    ah,P$TRIG2
  2261.     jnz    expi70        ; quit end
  2262. ;
  2263. expi48:    call    dspcros        ; display cross cursor
  2264.     jmp    expi40        ; go to get pad state
  2265. ;-------------------------------
  2266. ; cross cursor left
  2267. ;-------------------------------
  2268. expi50:    mov    eax,cura    ; current x position
  2269.     dec    eax        ; decrement
  2270.     cmp    eax,SCRX    ; check limit
  2271.     jae    expi52        ; OK!
  2272.     mov    eax,SCRX    ; correction
  2273. expi52:    mov    cura,eax    ; save x position
  2274.     jmp    expi10        ; go to display
  2275. ;-------------------------------
  2276. ; cross cursor right
  2277. ;-------------------------------
  2278. expi55:    mov    eax,cura    ; current x position
  2279.     inc    eax        ; increment
  2280.     cmp    eax,SCRX+SCRW    ; check limit
  2281.     jb    expi52        ; OK!
  2282.     mov    eax,SCRX+SCRW-1    ; correction
  2283.     jmp    expi52        ; go to save
  2284. ;-------------------------------
  2285. ; cross cursor up
  2286. ;-------------------------------
  2287. expi60:    mov    eax,curb    ; current y position
  2288.     dec    eax        ; decrement
  2289.     cmp    eax,SCRY    ; check limit
  2290.     jae    expi62        ; OK!
  2291.     mov    eax,SCRY    ; correction
  2292. expi62:    mov    curb,eax    ; save y position
  2293.     jmp    expi10        ; go to dislay
  2294. ;-------------------------------
  2295. ; crosss cursor down
  2296. ;-------------------------------
  2297. expi65:    mov    eax,curb    ; current y position
  2298.     inc    eax        ; increment
  2299.     cmp    eax,SCRY+SCRH    ; check limit
  2300.     jb    expi62        ; OK!
  2301.     mov    eax,SCRY+SCRH-1    ; correction
  2302.     jmp    expi62        ; go to save
  2303. ;-------------------------------
  2304. ; quit end
  2305. ;-------------------------------
  2306. expi70:    mov    al,palnum    ; resotre color number
  2307.     mov    colnum,al
  2308.     jmp    indc10        ; return to color number select mode
  2309.  
  2310. ;*******************************
  2311. ; dspcros : dsplay cross cursor
  2312. ;
  2313. ; in : cura = current x position
  2314. ;      curb = current y position
  2315. ;      es = VRAM selector
  2316. ; use: ecx,edi
  2317. ;
  2318. dspcros    proc
  2319. ;-------------------------------
  2320. ; horizon line
  2321. ;-------------------------------
  2322.     imul    edi,curb,VRAMW
  2323.     add    edi,SCRX    ; line start address
  2324.     mov    ecx,SCRW/4
  2325. dscrs1:    not    dword ptr es:[edi]
  2326.     add    edi,4
  2327.     loop    dscrs1
  2328. ;-------------------------------
  2329. ; vertical line
  2330. ;-------------------------------
  2331.     mov    edi,SCRY*VRAMW
  2332.     add    edi,cura    ; line start address
  2333.     mov    ecx,SCRH
  2334. dscrs2:    not    byte ptr es:[edi]
  2335.     add    edi,VRAMW
  2336.     loop    dscrs2
  2337.     ret
  2338. dspcros    endp
  2339. extpix    endp
  2340.  
  2341. ;*******************************
  2342. ; setcs : set color step
  2343. ;*******************************
  2344. setcs    proc
  2345. ;-------------------------------
  2346. ; initialize
  2347. ;-------------------------------
  2348.     mov    esi,offset msetcs
  2349.     call    dspmenu        ; display menu items
  2350.     mov    count1,1    ; color step
  2351.     mov    count2,1    ; color step change unit
  2352.     mov    hbnum,0        ; auto change flag off
  2353.     mov    currgb,P$FWD    ; auto command
  2354.     mov    ax,count2    ; display current change unit
  2355.     mov    edi,LCSTEP1
  2356.     call    putdec
  2357.     xor    ax,ax        ; wait no press state
  2358.     call    waitp
  2359. ;-------------------------------
  2360. ; display screen
  2361. ;-------------------------------
  2362. stcs10:    mov    ax,count1    ; display current step
  2363.     mov    edi,LCSTEP2
  2364.     call    putdec
  2365. ;
  2366.     mov    esi,offset work1    ; pallet packet
  2367.     mov    dword ptr [esi],0    ; initialize pallet number & levels
  2368.     mov    bx,PALSBN        ; set pallet block counter
  2369.     movzx    eax,count1        ; color step
  2370.     mov    ecx,PALSBR-1        ; set rest pallet number
  2371. stcs12:    call    waitv            ; wait VSYNC
  2372. stcs14:    inc    byte ptr [esi]        ; next pallet number
  2373.     add    [esi+1],eax        ; set new level
  2374.     call    setpal            ; set pallet code
  2375.     loop    stcs14
  2376.     mov    ecx,PALSBS        ; set pallet block size
  2377.     dec    bx
  2378.     jnz    stcs12
  2379. ;-------------------------------
  2380. ; command input
  2381. ;-------------------------------
  2382. stcs30:    call    getpad        ; get pad state
  2383. stcs32:    cmp    al,P$FWD
  2384.     je    stcs50        ; step up
  2385.     cmp    al,P$BACK
  2386.     je    stcs55        ; step down
  2387.     cmp    al,P$LEFT
  2388.     je    stcs60        ; unit up
  2389.     cmp    al,P$RIGHT
  2390.     je    stcs65        ; unit    down
  2391.     cmp    al,P$RUN
  2392.     je    stcs70        ; switch auto change
  2393. ;
  2394.     cmp    hbnum,0        ; check auto change flag
  2395.     je    stcs34        ; off
  2396.     mov    al,currgb    ; load auto command
  2397.     jmp    stcs32        ; go to dispatch
  2398.  
  2399. stcs34:    test    ah,P$TRIG2
  2400.     jnz    stcs80        ; cancel
  2401.     test    ah,P$TRIG1
  2402.     jz    stcs30        ; invalid
  2403. ;-------------------------------
  2404. ; decision end
  2405. ;-------------------------------
  2406.     cmp    spflg,TRUE    ; check save pallet flag
  2407.     je    stcs40
  2408.     call    savpal        ; save all pallets
  2409.     mov    spflg,TRUE
  2410. ;
  2411. stcs40:    mov    edi,offset palbuf    ; pallet buffer
  2412.     mov    ecx,USRCN        ; set pallet number counter
  2413.     movzx    eax,count1        ; color step
  2414.     xor    edx,edx            ; initialize color level
  2415. stcs42:    add    edi,3        ; next pallet address
  2416.     add    edx,eax        ; next color level
  2417.     mov    [edi],edx    ; set color level + 1
  2418.     loop    stcs42
  2419.     jmp    chgcol        ; return to color menu
  2420. ;-------------------------------
  2421. ; step up or down
  2422. ; in : al = command code
  2423. ;-------------------------------
  2424. stcs50:    mov    currgb,al    ; set auto command
  2425.     mov    ax,count2    ; change unit
  2426.     add    count1,ax    ; step up
  2427.     jnz    stcs10        ; go to change pallet
  2428.     inc    count1        ; skip zero step
  2429.     jmp    stcs10
  2430. ;
  2431. stcs55:    mov    currgb,al    ; set auto command
  2432.     mov    ax,count2    ; change unit
  2433.     sub    count1,ax    ; step down
  2434.     jnz    stcs10        ; go to change pallet
  2435.     dec    count1        ; skip zero step
  2436.     jmp    stcs10
  2437. ;-------------------------------
  2438. ; unit up or down
  2439. ;-------------------------------
  2440. stcs60:    inc    count2        ; cahnge unit up
  2441.     jns    stcs62
  2442.     dec    count2
  2443. stcs62:    call    waitv        ; wait VSYNC trigger
  2444.     mov    ax,count2    ; display current change unit
  2445.     mov    edi,LCSTEP1
  2446.     call    putdec
  2447.     jmp    stcs30        ; go to pad input
  2448. ;
  2449. stcs65:    dec    count2        ; change unit down
  2450.     jnz    stcs62
  2451.     inc    count2
  2452.     jmp    stcs62        ; go to display
  2453. ;-------------------------------
  2454. ; auto change switch
  2455. ;-------------------------------
  2456. stcs70:    not    hbnum        ; switch auto change flag
  2457.     xor    ax,ax        ; wait no press state
  2458.     call    waitp
  2459.     jmp    stcs30        ; go to pad input
  2460. ;-------------------------------
  2461. ; quit end
  2462. ;-------------------------------
  2463. stcs80:    call    setdp        ; set display pallet by old data
  2464.     jmp    chgcol        ; return to color menu
  2465. setcs    endp
  2466.  
  2467. ;*******************************
  2468. ; grad : gradation
  2469. ;*******************************
  2470. grad    proc
  2471. ;-------------------------------
  2472. ; initialize
  2473. ;-------------------------------
  2474.     mov    esi,offset mgrad
  2475.     call    dspmenu        ; display menu items
  2476.     mov    count1,111b    ; color number 1 = White
  2477.     mov    count2,000b    ; color number 250 = Black
  2478.     mov    hbnum,0        ; select number = 250
  2479.     mov    edi,(MENUY+60-17+2)*VRAMW+MENUX+40
  2480.     mov    al,1        ; color number 1
  2481.     call    gradp        ; draw gradation panel
  2482.     mov    edi,(MENUY+120-17+2)*VRAMW+MENUX+40
  2483.     mov    al,250        ; color number 250
  2484.     call    gradp        ; draw gradation panel
  2485.     call    dspgcn        ; display gradation color number
  2486. ;-------------------------------
  2487. ; change pallet
  2488. ;-------------------------------
  2489. grad20:    mov    esi,offset work1    ; pallet packet
  2490.     call    makgd            ; make gradation data
  2491.     mov    bx,PALSBN        ; set pallet block counter
  2492.     mov    ecx,PALSBR-1        ; set rest pallet number execpt 0
  2493. grad26:    call    waitv            ; wait VSYNC
  2494. grad28:    call    setpal            ; set pallet code
  2495.     inc    byte ptr [esi]        ; next pallet number
  2496.     mov    al,[esi+4]
  2497.     add    [esi+1],al        ; new blue level
  2498.     mov    al,[esi+5]
  2499.     add    [esi+2],al        ; new red level
  2500.     mov    al,[esi+6]
  2501.     add    [esi+3],al        ; new green level
  2502.     loop    grad28
  2503.     mov    ecx,PALSBS        ; set pallet full block size
  2504.     dec    bx
  2505.     jnz    grad26
  2506. ;-------------------------------
  2507. ; command input
  2508. ;-------------------------------
  2509. grad30:    xor    ax,ax        ; wait no press state
  2510.     call    waitp
  2511. grad32:    call    getpad        ; get pad state
  2512.     cmp    al,P$RIGHT
  2513.     je    grad50        ; next color
  2514.     cmp    al,P$LEFT
  2515.     je    grad60        ; previous color
  2516.     cmp    al,P$SEL
  2517.     je    grad70        ; select 0 or 250
  2518.     test    ah,P$TRIG2
  2519.     jnz    grad80        ; cancel
  2520.     test    ah,P$TRIG1
  2521.     jz    grad32        ; invalid
  2522. ;-------------------------------
  2523. ; decision end
  2524. ;-------------------------------
  2525.     cmp    spflg,TRUE    ; check save pallet flag
  2526.     je    grad40
  2527.     call    savpal        ; save all pallets
  2528.     mov    spflg,TRUE
  2529. ;
  2530. grad40:    mov    esi,offset work1    ; pallet packet
  2531.     call    makgd            ; make gradation data
  2532.     mov    edi,offset palbuf+3    ; user pallet buffer address
  2533.     mov    ecx,USRCN        ; set pallet number counter
  2534.     mov    ax,[esi+1]    ; blue,red start level
  2535.     mov    dl,[esi+3]    ; green start level
  2536. grad42:    mov    [edi],ax    ; set green,red level
  2537.     mov    [edi+2],dl    ; set blue level
  2538.     add    edi,3        ; next pallet address
  2539.     add    al,[esi+4]    ; new blue level
  2540.     add    ah,[esi+5]    ; new red level
  2541.     add    dl,[esi+6]    ; new green level
  2542.     loop    grad42
  2543.     jmp    chgcol        ; return to color menu
  2544. ;-------------------------------
  2545. ; next color
  2546. ;-------------------------------
  2547. grad50:    cmp    hbnum,0        ; check destination
  2548.     je    grad52
  2549.     inc    count1
  2550.     jmp    grad20
  2551. grad52:    inc    count2
  2552.     jmp    grad20
  2553. ;-------------------------------
  2554. ; previous color
  2555. ;-------------------------------
  2556. grad60:    cmp    hbnum,0        ; check destination
  2557.     je    grad62        ; color 250
  2558.     or    count1,1000b
  2559.     dec    count1
  2560.     jmp    grad20
  2561. grad62:    or    count2,1000b
  2562.     dec    count2
  2563.     jmp    grad20
  2564. ;-------------------------------
  2565. ; select 0 or 250
  2566. ;-------------------------------
  2567. grad70:    not    hbnum        ; change destination color
  2568.     call    dspgcn        ; display gradatino color number
  2569.     jmp    grad30        ; go to next command
  2570. ;-------------------------------
  2571. ; cancel end
  2572. ;-------------------------------
  2573. grad80:    call    setdp        ; set display pallet by old data
  2574.     jmp    chgcol        ; return to color menu
  2575.  
  2576. ;*******************************
  2577. ; gradp : draw gradation panel
  2578. ;
  2579. ; in : edi = start address
  2580. ;      al = color code
  2581. ;
  2582. gradp    proc
  2583.     mov    bx,16        ; set hight counter
  2584.     mov    ah,al
  2585. gradp1:    mov    ecx,76/2    ; set width counter
  2586.     rep    stosw
  2587.     add    edi,VRAMW-76
  2588.     dec    bx
  2589.     jnz    gradp1
  2590.     ret
  2591. gradp    endp
  2592.  
  2593. ;*******************************
  2594. ; dspgcn : display gradation
  2595. ;      color number
  2596. ;   select item is intensified
  2597. ;
  2598. ; in : hbnum = color number flag
  2599. ;         00 = 250
  2600. ;         FF = 1
  2601. ; call: color
  2602. ;
  2603. gcnstr1    dw    MENUX+8+16,MENUY+60,1    ; lowest color number string
  2604.     db    "1"
  2605. gcnstr2    dw    MENUX+8,MENUY+120,3    ; highest color number string
  2606.     db    "250"
  2607. ;
  2608. dspgcn    proc
  2609.     mov    ax,(C$DARK shl 8)+C$INT
  2610.     cmp    hbnum,0
  2611.     je    dpgcn1            ; highest number
  2612.     xchg    ah,al
  2613. dpgcn1:    push    ax
  2614.     mov    al,ah
  2615.     call    color            ; set color
  2616.     mov    edi,offset egbwork    ; EGB work address
  2617.     mov    esi,offset gcnstr1    ; lowest number
  2618.     mov    ah,60h            ; display string
  2619.     call    pword ptr fs:[20h]
  2620.     pop    ax
  2621.     call    color            ; set color
  2622.     mov    esi,offset gcnstr2    ; highest number
  2623.     mov    ah,60h            ; display string
  2624.     call    pword ptr fs:[20h]
  2625.     ret
  2626. dspgcn    endp
  2627.  
  2628. ;*******************************
  2629. ; makgd : make gradation data
  2630. ;
  2631. ; in : esi = work buffer
  2632. ;        0(1) pallet number
  2633. ;        1(1) blue level
  2634. ;        2(1) red level
  2635. ;        3(1) green level
  2636. ;        4(1) blue step
  2637. ;        5(1) red step
  2638. ;        6(1) green step
  2639. ;      count1 = color 0 level flag
  2640. ;      count2 = color 250 level flag
  2641. ;
  2642. makgd    proc
  2643.     mov    byte ptr [esi],1    ; initialize pallet number
  2644.     mov    dx,count1        ; color 1 level flag
  2645.     mov    bx,count2        ; color 250 level flag
  2646.     mov    ecx,3
  2647. makgd1:    mov    ax,255-USRCN        ; AL = lowest level
  2648.     shr    dx,1
  2649.     jnc    makgd2
  2650.     mov    ax,(-1 shl 8)+USRCN    ; AL = highest level
  2651. makgd2:    mov    [esi+ecx],al        ; set initial level
  2652.     shr    bx,1
  2653.     adc    ah,0
  2654.     mov    [esi+ecx+3],ah        ; set level step (-1|0|+1)
  2655.     loop    makgd1
  2656.     ret
  2657. makgd    endp
  2658. grad    endp
  2659.  
  2660. ;*******************************
  2661. ; cload : load color data
  2662. ;*******************************
  2663. cload    proc
  2664.     mov    exts,EXTCOL        ; set extension
  2665.     call    open            ; file open
  2666.     jc    clod90            ; quit
  2667.     mov    bx,ax            ; file handel
  2668. ;
  2669.     cmp    spflg,TRUE        ; check save pallet flag
  2670.     je    clod10
  2671.     call    savpal            ; save all pallets
  2672.     mov    spflg,TRUE
  2673. ;
  2674. clod10:    mov    edx,offset palbuf    ; pallet buffer
  2675.     mov    ecx,(1+USRCN)*3        ; color data byte size
  2676.     mov    ah,3Fh            ; read file
  2677.     int    21h
  2678.     mov    ah,3Eh            ; file close
  2679.     int    21h
  2680. ;
  2681.     call    setdp            ; set display pallet
  2682. clod90:    jmp    chgcol            ; return to color menu
  2683. cload    endp
  2684.  
  2685. ;*******************************
  2686. ; csave : save color data
  2687. ;*******************************
  2688. csave    proc
  2689. csav10:    mov    eax,EXTCOL    ; extension
  2690.     call    create        ; file create
  2691.     jc    csav90        ; quit
  2692. ;
  2693.     mov    edx,offset palbuf
  2694.     mov    ecx,(1+USRCN)*3    ; data byte size
  2695.     mov    bx,ax        ; file handle
  2696.     mov    ah,40h        ; write
  2697.     int    21h
  2698.     pushf
  2699.     mov    ah,3Eh        ; file close
  2700.     int    21h
  2701.     popf
  2702.     jc    csav10        ; error then input repeat
  2703. csav90:    jmp    chgcol        ; return to color menu
  2704. csave    endp
  2705.  
  2706. ;*******************************
  2707. ; crest : restore color data
  2708. ;*******************************
  2709. crest    proc
  2710.     mov    esi,offset palbak    ; backup pallets
  2711.     mov    edi,offset palbuf    ; pallet buffer
  2712.     mov    ecx,1+USRCN        ; number of pallets
  2713. crest1:    lodsw
  2714.     xchg    [edi],ax
  2715.     mov    [esi-2],ax
  2716.     lodsb
  2717.     xchg    [edi+2],al
  2718.     mov    [esi-1],al
  2719.     add    edi,3
  2720.     loop    crest1
  2721. ;
  2722.     mov    spflg,FALSE    ; clear save pallet flag
  2723.     call    setdp        ; set display pallets
  2724.     jmp    chgcol        ; return to color menu
  2725. crest    endp
  2726.  
  2727.  
  2728. ;*******************************
  2729. ; boxdwn : box down
  2730. ;    look like down area
  2731. ;    by C$LIGHT,C$DARK
  2732. ;
  2733. ; in : esi = box data base
  2734. ;         0 : base address
  2735. ;         4 : width(4*n)
  2736. ;         6 : hight
  2737. ;      al = fill color code
  2738. ; use: bx,ecx,edx
  2739. ;
  2740. boxdwn    proc
  2741.     push    esi
  2742.     push    edi
  2743.     mov    ah,al            ; extend AL to EAX
  2744.     mov    dx,ax
  2745.     shl    eax,16
  2746.     mov    ax,dx
  2747.     mov    edi,[esi].boxadr    ; start VRAM address
  2748.     mov    bx,[esi].boxh        ; set hight counter
  2749.     movzx    esi,[esi].boxw        ; width
  2750.     mov    edx,esi
  2751.     sub    esi,VRAMW        ; negative line distance
  2752.     shr    edx,2            ; double word counter
  2753. bxdw10:    mov    byte ptr es:[edi-1],C$DARK
  2754.     mov    ecx,edx            ; set width counter
  2755.     rep    stosd
  2756.     mov    byte ptr es:[edi],C$LIGHT
  2757.     sub    edi,esi            ; next line address
  2758.     dec    bx            ; line count down
  2759.     jnz    bxdw10
  2760.     pop    edi
  2761.     pop    esi
  2762.     ret
  2763. boxdwn    endp
  2764.  
  2765. ;*******************************
  2766. ; revfr : reverse frame
  2767. ;
  2768. ; in : esi = box address
  2769. ;       0 : x position
  2770. ;       2 : y position
  2771. ;       4 : width
  2772. ;       6 : hight
  2773. ; use: eax,ebx,ecx,edx
  2774. ;
  2775. revfr    proc
  2776.     push    edi
  2777.     movzx    eax,word ptr [esi+2]    ; y position
  2778.     imul    eax,VRAMW
  2779.     movzx    edi,word ptr [esi]
  2780.     add    edi,eax            ; base address
  2781. ;
  2782.     movzx    ecx,word ptr [esi+4]    ; width counter
  2783.     mov    edx,ecx            ; save
  2784. revf10:    not    byte ptr es:[edi+ecx-1]    ; reverse top line
  2785.     loop    revf10
  2786. ;
  2787.     add    edi,VRAMW        ; next line address
  2788.     movzx    ecx,word ptr [esi+6]    ; hight
  2789.     sub    ecx,2            ; intermediate lines counter
  2790. revf20:    not    byte ptr es:[edi]    ; reverse left pixcel
  2791.     not    byte ptr es:[edi+edx-1]    ; reverse right pixcel
  2792.     add    edi,VRAMW        ; next line address
  2793.     loop    revf20
  2794. ;
  2795.     mov    ecx,edx            ; width counter
  2796. revf30:    not    byte ptr es:[edi+ecx-1]    ; reverse bottom line
  2797.     loop    revf30
  2798.     pop    edi
  2799.     ret
  2800. revfr    endp
  2801.  
  2802. ;*******************************
  2803. ; boxup : look like box up
  2804. ;      use C$LIGHT,C$DARK
  2805. ;
  2806. ; in : edi = box start address
  2807. ;      ax = box width
  2808. ;      dx = box hight
  2809. ; use: none
  2810. ;
  2811. boxup    proc
  2812.     push    edi
  2813.     push    ax
  2814.     push    ebx
  2815.     push    ecx
  2816.     push    dx
  2817.     movzx    ebx,ax        ; save box width
  2818.     mov    al,C$LIGHT
  2819.     mov    ecx,ebx        ; width counter
  2820.     rep    stosb        ; draw top line
  2821.     sub    edi,ebx
  2822.     add    edi,VRAMW    ; next line address
  2823. ;
  2824.     sub    dx,2
  2825.     movzx    ecx,dx        ; middle line counter
  2826. bxup10:    mov    es:[edi],al
  2827.     mov    byte ptr es:[edi+ebx-1],C$DARK
  2828.     add    edi,VRAMW    ; next line address
  2829.     loop    bxup10
  2830. ;
  2831.     mov    al,C$DARK
  2832.     mov    ecx,ebx        ; width counter
  2833.     rep    stosb        ; draw bottom line
  2834.     pop    dx
  2835.     pop    ecx
  2836.     pop    ebx
  2837.     pop    ax
  2838.     pop    edi
  2839.     ret
  2840. boxup    endp
  2841.  
  2842. ;*******************************
  2843. ; chgsc : string color change
  2844. ;     except for right pixcel
  2845. ;
  2846. ; in : edi = box start address
  2847. ;      bx = box width
  2848. ;      al = destination color
  2849. ;      ah = source color
  2850. ;      es = VRAM selector
  2851. ; use: ecx,edx,ebp
  2852. ;
  2853. chgsc    proc
  2854.     push    edi
  2855.     movzx    ebx,bx
  2856.     mov    ebp,VRAMW
  2857.     sub    ebp,ebx        ; distance between lines
  2858.     mov    dx,16        ; string hight counter
  2859. cgbx10:    mov    ecx,ebx        ; set width counter
  2860. cgbx12:    repne    scasb
  2861.     jcxz    cgbx14
  2862.     mov    es:[edi-1],ah    ; change color
  2863.     jmp    cgbx12
  2864. cgbx14:    add    edi,ebp        ; next line address
  2865.     dec    dx
  2866.     jnz    cgbx10
  2867.     pop    edi
  2868.     ret
  2869. chgsc    endp
  2870.  
  2871. ;*******************************
  2872. ; color : set foreground color
  2873. ;
  2874. ; in : al = color code
  2875. ; use: ax,edx,edi
  2876. ;
  2877. color    proc
  2878.     mov    edi,offset egbwork    ; EGB work address
  2879.     movzx    edx,al            ; color code
  2880.     mov    ax,0700h        ; set foreground color
  2881.     call    pword ptr fs:[20h]
  2882.     ret
  2883. color    endp
  2884.  
  2885. ;*******************************
  2886. ; dspss : display strings
  2887. ;
  2888. ; in : bx = string index address
  2889. ;      al = string color
  2890. ;      fs = TOWNS BIOS
  2891. ; call: color
  2892. ; use: ax,bx,ecx,edi
  2893. ;
  2894. dspss    proc
  2895.     push    esi
  2896.     call    color            ; set color
  2897.     mov    edi,offset egbwork    ; EGB work address
  2898.     movzx    ecx,word ptr [bx]    ; number of string
  2899. dpss10:    add    bx,2
  2900.     movsx    esi,word ptr [bx]
  2901.     mov    ah,60h
  2902.     call    pword ptr fs:[20h]
  2903.     loop    dpss10
  2904.     pop    esi
  2905.     ret
  2906. dspss    endp
  2907.  
  2908. ;*******************************
  2909. ; dspfp : display frame parameter
  2910. ;     posx,posy,reso
  2911. ;
  2912. ; use: putfp
  2913. ;
  2914. dspfp    proc
  2915.     mov    eax,posx    ; position x
  2916.     mov    edi,LPOSX
  2917.     call    putfp
  2918.     mov    eax,posy    ; position y
  2919.     neg    eax
  2920.     mov    edi,LPOSY
  2921.     call    putfp
  2922.     mov    eax,reso    ; resolution
  2923.     mov    edi,LRESO
  2924.     call    putfp
  2925.     ret
  2926. dspfp    endp
  2927.  
  2928. ;*******************************
  2929. ; dspmenu : display menu items
  2930. ;
  2931. ; in : esi = menu items index
  2932. ;        0(2) buttons pointer
  2933. ;        2(2) buttons number
  2934. ;        4(2) strings pointer
  2935. ; call: boxdwn,boxup,dspss
  2936. ; use: all
  2937. ;
  2938. dspmenu    proc
  2939.     mov    edi,esi            ; save index pointer
  2940.     mov    esi,offset menubox    ; menu box pointer
  2941.     mov    al,C$PANEL        ; with panel color
  2942.     call    boxdwn            ; clear box
  2943. ;
  2944.     push    edi            ; save index pointer
  2945.     mov    si,[edi].butptr        ; buttons pointer
  2946.     movzx    ecx,[edi].butnum    ; buttons number
  2947. dsme10:    mov    edi,[si].butadr        ; start address
  2948.     mov    ax,[si].butw        ; box width
  2949.     mov    dx,[si].buth        ; box hight
  2950.     call    boxup            ; button up
  2951.     add    si,8            ; next box
  2952.     loop    dsme10
  2953.     pop    edi            ; load index pointer
  2954. ;
  2955.     mov    bx,[edi].strptr        ; strings pointer
  2956.     mov    al,C$DARK        ; dark shadow color
  2957.     call    dspss            ; display strings
  2958.     ret
  2959. dspmenu    endp
  2960.  
  2961. ;*******************************
  2962. ; getpad : get pad button state
  2963. ;
  2964. ; out: ah = trigger
  2965. ;      al = move, run and select
  2966. ; use: dx
  2967. ;
  2968. getpad    proc
  2969.     xor    ax,ax
  2970.     mov    dx,04D6h    ; set pad output register
  2971.     mov    al,00010011b
  2972.     out    dx,al
  2973.     mov    dx,04D0h    ; get pad 1 input
  2974.     in    al,dx
  2975.     test    al,01000000b    ; check COM input
  2976.     jz    gtpd22        ; no exist
  2977.     call    gtpd30        ; analyze pad 1 state
  2978.     test    ax,ax        ; press any key ?
  2979.     jnz    gtpd99        ; yes
  2980. ;
  2981. gtpd22:    mov    dx,04D6h    ; set pad output register
  2982.     mov    al,00101100b
  2983.     out    dx,al
  2984.     mov    dx,04D2h    ; get pad 2 input
  2985.     in    al,dx
  2986.     test    al,01000000b    ; check COM input
  2987.     jz    gtpd99        ; no exist
  2988.     call    gtpd30        ; analyze pad 2 state
  2989. gtpd99:    ret
  2990.  
  2991. gtpd30:    mov    ah,al
  2992.     not    ah
  2993.     and    ah,00110000b    ; mask off trigger bits
  2994.     shr    ah,4        ; make return data
  2995.     and    al,00001111b    ; mask off other button state
  2996.     cmp    al,0111b    ; check RIGHT state
  2997.     je    gtpd50        ; on
  2998.     cmp    al,1011b    ; check LEFT state
  2999.     je    gtpd52        ; on
  3000.     cmp    al,1101b    ; check BACK state
  3001.     je    gtpd54        ; on
  3002.     cmp    al,1110b    ; check FWD state
  3003.     je    gtpd56        ; on
  3004.     cmp    al,0011b    ; check RUN state
  3005.     je    gtpd58        ; on
  3006.     cmp    al,1100b    ; check SELECT state
  3007.     je    gtpd60        ; on
  3008. ;
  3009.     xor    al,al        ; not press
  3010.     ret
  3011. gtpd50: mov    al,P$RIGHT 
  3012.     ret
  3013. gtpd52:    mov    al,P$LEFT
  3014.     ret
  3015. gtpd54:    mov    al,P$BACK
  3016.     ret
  3017. gtpd56: mov    al,P$FWD
  3018.     ret
  3019. gtpd58:    mov    al,P$RUN
  3020.     ret
  3021. gtpd60:    mov    al,P$SEL
  3022.     ret
  3023. getpad    endp
  3024.  
  3025. ;*******************************
  3026. ; waitp : wait special pad state
  3027. ;
  3028. ; in : ax = pad state
  3029. ; call: getpad
  3030. ; use: ax,cx,dx
  3031. ;
  3032. waitp    proc
  3033.     mov    cx,ax    ; dave destination state
  3034. waip10:    call    getpad    ; get pad state
  3035.     cmp    cx,ax    ; compare pad state
  3036.     jne    waip10    ; difference
  3037.     ret
  3038. waitp    endp
  3039.  
  3040. ;*******************************
  3041. ; waitv : wait VSYNC happen
  3042. ;
  3043. ; use: none
  3044. ;
  3045. waitv    proc
  3046.     push    dx
  3047.     push    ax
  3048.     mov    dx,0FDA0h    ; SUB status register I/O address
  3049. waiv10:    in    al,dx
  3050.     test    al,1b        ; VSYNC
  3051.     jnz    waiv10        ; wait VSYNC off
  3052. waiv20:    in    al,dx
  3053.     test    al,1b        ; VSYNC
  3054.     jz    waiv20        ; wait VSYNC on
  3055.     pop    ax
  3056.     pop    dx
  3057.     ret
  3058. waitv    endp
  3059.  
  3060.  
  3061. ;*******************************
  3062. ; repable : check repeatble
  3063. ;
  3064. ; in : repcnt = repeat count
  3065. ; out: cf = able is clear
  3066. ; call: waitv
  3067. ; use: none
  3068. ;
  3069. repable    proc
  3070.     call    waitv
  3071.     inc    repcnt
  3072.     jz    repab9        ; first input
  3073.     cmp    repcnt,PADREP
  3074.     jb    repabE        ; invalid
  3075. repab9:    mov    repcnt,0    ; clear counter
  3076.     clc            ; repeatable
  3077. repabE:    ret
  3078. repable    endp
  3079.  
  3080. ;*******************************
  3081. ; select : select menu item
  3082. ;
  3083. ; in : bx = selector data address
  3084. ;      fs = TOWNS BIOS
  3085. ; out: ax = selector number
  3086. ; err: cf = set by escape
  3087. ; call: boxup,dspss,waitp
  3088. ;      getpad,repable,color
  3089. ; use: ax,ecx,dx,esi
  3090. ;
  3091. select    proc
  3092.     mov    repcnt,INIREP    ; clear pad input counter
  3093. ;-------------------------------
  3094. ; initialize screen
  3095. ;-------------------------------
  3096.     push    bx
  3097.     movzx    ecx,word ptr [bx+2]    ; set item counter
  3098.     add    bx,4        ; first item pointer address
  3099.     mov    ax,MENUW-6    ; selector box width
  3100.     mov    dx,19        ; selector box hight
  3101. sel10:    mov    di,[bx]        ; item pointer
  3102.     movsx    edi,word ptr [di+2]    ; item y position
  3103.     sub    edi,16        ; box top y position
  3104.     imul    edi,VRAMW
  3105.     add    edi,MENUX+3    ; box base VRAM address
  3106.     call    boxup        ; look like box up
  3107.     add    bx,2        ; next item pointer address
  3108.     loop    sel10
  3109.     pop    bx
  3110. ;
  3111.     push    bx
  3112.     add    bx,2        ; strings index address
  3113.     mov    al,C$DARK    ; dark shdow color
  3114.     call    dspss        ; display strings
  3115.     pop    bx
  3116. ;
  3117.     xor    ax,ax        ; wait no press state
  3118.     call    waitp
  3119. ;-------------------------------
  3120. ; display current item
  3121. ; in : bx = menu data address
  3122. ;-------------------------------
  3123. sel20:    mov    si,[bx]            ; current item number
  3124.     test    si,si            ; check under limit
  3125.     jns    sel22            ; OK!
  3126.     mov    si,[bx+2]        ; arround highest number
  3127.     dec    si
  3128. sel22:    cmp    si,[bx+2]        ; check upper limit
  3129.     jb    sel24            ; OK!
  3130.     xor    si,si            ; arround lowest number
  3131. sel24:    mov    [bx],si            ; save adjust number
  3132. ;
  3133.     shl    si,1
  3134.     movsx    esi,word ptr [bx+si+4]    ; current string address
  3135.     movsx    edi,word ptr [esi+2]    ; item y position
  3136.     sub    edi,15        ; box top panel y position
  3137.     imul    edi,VRAMW
  3138.     add    edi,MENUX+4    ; box top panel base VRAM address
  3139.     push    bx
  3140.     mov    bx,MENUW-8    ; box top panel width
  3141.     mov    ax,C$DARK+C$INT*256
  3142.     call    chgsc        ; change box color
  3143.     pop    bx
  3144. ;-------------------------------
  3145. ; input pad
  3146. ; in : bx = selector data address
  3147. ;-------------------------------
  3148. sel30:    call    getpad        ; get pad button state
  3149.     cmp    al,P$FWD
  3150.     je    sel40        ; cursor up
  3151.     cmp    al,P$BACK
  3152.     je    sel44        ; cursor down
  3153.     mov    repcnt,INIREP    ; clear counter
  3154.     test    ah,P$TRIG2
  3155.     jnz    sel38        ; escape
  3156.     test    ah,P$TRIG1
  3157.     jz    sel30        ; invalid
  3158. ;
  3159.     mov    ax,[bx]        ; select item number
  3160.     clc            ; clear carry
  3161.     ret
  3162. sel38:    stc            ; set carry
  3163.     ret
  3164. ;-------------------------------
  3165. ; move cursor
  3166. ; in : edi = current box top address
  3167. ;      bx = menu data address
  3168. ;-------------------------------
  3169. sel40:    call    repable        ; repeatalbe ?
  3170.     jc    sel30        ; invalid
  3171.     dec    word ptr [bx]    ; to lower item
  3172.     jmp    short sel48
  3173. ;
  3174. sel44:    call    repable        ; repeatalbe ?
  3175.     jc    sel30        ; invalid
  3176.     inc    word ptr [bx]    ; to upper item
  3177. ;
  3178. sel48:    push    bx
  3179.     mov    bx,MENUW-8    ; box top panel width
  3180.     mov    ax,C$INT+C$DARK*256
  3181.     call    chgsc        ; change string color
  3182.     pop    bx
  3183.     jmp    sel20
  3184. select    endp
  3185.  
  3186. ;*******************************
  3187. ; dspmain : display main
  3188. ;       mandelbrot figure
  3189. ;
  3190. ; in : curstat = current display state
  3191. ;      step = display step
  3192. ; out: curstat = new display state
  3193. ;      step = new step
  3194. ; err: cf = set by interrupted
  3195. ; call: dspmenu,putdec,getpad
  3196. ;       dsp8s,dsp3q
  3197. ; use: all
  3198. ;
  3199. dspmain    proc
  3200.     cmp    curstat,DS$FULL    ; if full figure display completion
  3201.     je    dsma99        ; then end with do nothing
  3202.     mov    esi,offset mdrawon    ; display menu items
  3203.     call    dspmenu
  3204.     cmp    curstat,DS$ON    ; dispaly on the way ?
  3205.     je    dsma10        ; continue
  3206. ;
  3207.     mov    ax,8        ; display step number
  3208.     mov    edi,LDSTEP    ; display position
  3209.     call    putdec
  3210.     call    dsp8s        ; first display by 8 step
  3211.     mov    curstat,DS$ON    ; first display completion
  3212.     mov    step,4        ; set display step
  3213.     call    getpad        ; get pad state
  3214.     test    ah,P$TRIG2    ; press B button ?
  3215.     jnz    dsma90        ; interrupt
  3216. ;
  3217. dsma10:    mov    ax,step        ; display step
  3218.     mov    edi,LDSTEP    ; display position
  3219.     call    putdec
  3220.     call    dsp3q        ; display 3/4
  3221.     jc    dsma99        ; interrupted end
  3222.     shr    step,1        ; set next step
  3223.     jnz    dsma10
  3224.     mov    curstat,DS$FULL    ; display completion
  3225.     clc        ; clear carry for completed
  3226.     ret
  3227. dsma90: stc        ; set carry for interrupted
  3228. dsma99:    ret
  3229. dspmain    endp
  3230.  
  3231. ;*******************************
  3232. ; dspis : display initial screen
  3233. ;     and initial parameter
  3234. ;
  3235. ; in : idata= initial data
  3236. ;      islin = calculated lines
  3237. ;      es = VRAM selector
  3238. ; call: dspfp,putdec,calc
  3239. ; use: eax,ecx,edx,esi,edi,ebx,ebp
  3240. ;      count1
  3241. ;
  3242. dspis    proc
  3243. ;-------------------------------
  3244. ; initialize parameter & display
  3245. ;-------------------------------
  3246.     mov    posx,IPOSX    ; initial position x
  3247.     mov    posy,IPOSY    ; initial position y
  3248.     mov    reso,IRESO    ; initial resolution
  3249.     call    dspfp        ; display frame parameter
  3250.     mov    ax,ILIMIT    ; initial limit
  3251.     mov    limit,ax    ; set limit
  3252.     mov    edi,LLIMIT    ; display limit
  3253.     call    putdec
  3254.     mov    curstat,DS$FULL    ; display complete
  3255.     mov    step,0
  3256. ;-------------------------------
  3257. ; display calculated data
  3258. ;-------------------------------
  3259.     mov    esi,offset idata    ; calculated data address
  3260.     mov    ebp,(SCRY+SCRH/2-1)*VRAMW+SCRX    ; upper line VRAM address
  3261.     mov    ebx,(SCRY+SCRH/2)*VRAMW+SCRX    ; lower line VRAM address
  3262.     mov    dx,islin        ; set line counter
  3263.     test    dx,dx
  3264.     jz    dsis40
  3265. dsis20:    mov    edi,ebp            ; upper line VRAM address
  3266.     mov    ecx,SCRW/4        ; set screen width counter
  3267.     rep    movsd            ; write upper line
  3268.     sub    esi,SCRW        ; rewind data line address
  3269.     mov    edi,ebx            ; lower line VRAM address
  3270.     mov    ecx,SCRW/4        ; set screen width counter
  3271.     rep    movsd            ; write lower line
  3272.     sub    ebp,VRAMW        ; new upper line start address
  3273.     add    ebx,VRAMW        ; new lower line start address
  3274.     dec    dx
  3275.     jne    dsis20
  3276. ;-------------------------------
  3277. ; calculate & display rest lines
  3278. ; in : ebp = upper line VRAM address
  3279. ;      ebx = lower line VRAM address
  3280. ;      esi = data saving address
  3281. ;-------------------------------
  3282. dsis40:    movzx    eax,islin    ; calculated lines
  3283.     cmp    ax,SCRH/2
  3284.     jae    dsis90        ; needless
  3285. ;
  3286.     add    eax,SCRH/2    ; start y pixcel
  3287.     imul    eax,RESO    ; start y offset position
  3288.     add    eax,IPOSY    ; start y position
  3289.     mov    curb,eax    ; set start y position
  3290.     mov    edi,ebp        ; upper line VRAM address
  3291. dsis50:    mov    count2,SCRW    ; set screen width counter
  3292.     mov    cura,IPOSX    ; set position x
  3293. dsis52:    push    esi
  3294.     push    ebx
  3295.     push    edi
  3296.     call    calc        ; calculate repeat number
  3297.     pop    edi        ; upper pixcel VRAM address
  3298.     pop    ebx        ; lower pixcel VRAM address
  3299.     pop    esi        ; data saving address
  3300.     stosb            ; write upper pixcel
  3301.     mov    es:[ebx],al    ; write lower pixcel
  3302.     mov    [esi],al    ; save data
  3303.     inc    ebx        ; next lower pixcel address
  3304.     inc    esi        ; next saving address
  3305.     add    cura,IRESO    ; next x position
  3306.     dec    count2        ; line end ?
  3307.     jnz    dsis52
  3308.     sub    edi,VRAMW+SCRW    ; next upper line start address
  3309.     add    ebx,VRAMW-SCRW    ; next lower line start address
  3310.     add    curb,IRESO    ; next y positon
  3311.     inc    islin        ; line count up
  3312.     cmp    islin,SCRH/2    ; check line end
  3313.     jb    dsis50
  3314. ;
  3315. dsis90:    ret
  3316. dspis    endp
  3317.  
  3318. ;*******************************
  3319. ; dsp8s : display by 8 step
  3320. ;    don't permit interrupt
  3321. ;
  3322. ; call: calc
  3323. ; use: eax,ebx,ecx,edx,esi,edi
  3324. ;
  3325. dsp8s    proc
  3326.     mov    edi,SCRADR
  3327.     mov    count1,SCRH/8    ; set screen hight counter
  3328.     mov    eax,posy    ; set y position
  3329.     mov    curb,eax
  3330. ds8s10:    mov    count2,SCRW/8    ; set screen width counter
  3331.     mov    eax,posx    ; set x position
  3332.     mov    cura,eax
  3333. ds8s12:    push    edi
  3334.     call    calc        ; calculate repeat number
  3335.     pop    edi
  3336. ds8s20:    sub    ax,USRCN    ; adjust color code
  3337.     ja    ds8s20
  3338.     add    ax,USRCN
  3339.     mov    ah,al
  3340.     mov    dx,ax
  3341.     shl    eax,16
  3342.     mov    ax,dx
  3343.     mov    ecx,8
  3344. ds8s30:    mov    es:[edi],eax    ; write VRAM
  3345.     mov    es:[edi+4],eax    ; write VRAM
  3346.     add    edi,VRAMW
  3347.     loop    ds8s30
  3348.     sub    edi,VRAMW*8-8    ; next block VRAM address
  3349.     mov    eax,reso    ; resolution
  3350.     shl    eax,3        ; 8 step
  3351.     add    cura,eax    ; new current real part
  3352.     dec    count2        ; line end ?
  3353.     jnz    ds8s12
  3354.     add    edi,VRAMW*8-SCRW    ; new line start address
  3355.     mov    eax,reso    ; resolution
  3356.     shl    eax,3        ; 8 step
  3357.     add    curb,eax    ; new current imaginary part
  3358.     dec    count1        ; exist rest lines ?
  3359.     jnz    ds8s10
  3360.     ret
  3361. dsp8s    endp
  3362.  
  3363. ;*******************************
  3364. ; dsp3q : display 3/4
  3365. ;   check B button per lines
  3366. ;
  3367. ; in : step = display step(1,2,4,8)
  3368. ; out: cf = set by interruption
  3369. ; call: getpad,calc
  3370. ; use: eax,ebx,ecx,edx,esi,edi
  3371. ;
  3372. dsp3q    proc
  3373. ;-------------------------------
  3374. ; initialize
  3375. ;-------------------------------
  3376.     mov    esi,SCRADR    ; VRAM start address
  3377.     movzx    ebx,step    ; display step
  3378.     imul    eax,ebx,VRAMW    ; block line step
  3379.     sub    eax,SCRW    ; for rewind
  3380.     mov    bstep,eax    ; save block line VRAM step
  3381. ;
  3382.     mov    ax,SCRW        ; display screen width
  3383.     cwd            ; extend DX:AX
  3384.     div    bx        ; block number in horizon
  3385.     mov    hbnum,ax    ; save horizon block number
  3386.     mov    ax,SCRH        ; screen pixcel hight
  3387.     cwd            ; extend DX:AX
  3388.     div    bx         ; block number of vertical
  3389.     mov    count1,ax    ; set block hight counter
  3390. ;
  3391.     mov    eax,posy    ; set start y position
  3392.     mov    curb,eax
  3393.     imul    ebx,reso    ; position step
  3394.     mov    pstep,ebx    ; save position step
  3395. ;-------------------------------
  3396. ; start display a block line
  3397. ;-------------------------------
  3398. ds3q10:    call    getpad        ; get pad state
  3399.     test    ah,P$TRIG2    ; press B button ?
  3400.     jnz    ds3q95        ; interruption
  3401. ;
  3402.     mov    eax,posx    ; set block line x position
  3403.     mov    cura,eax
  3404.     mov    ax,hbnum    ; horizon block number
  3405.     mov    count2,ax    ; set block counter of 1 line
  3406. ;-------------------------------
  3407. ; calculate repeat number
  3408. ;-------------------------------
  3409. ds3q20:    bt    count1,0
  3410.     jc    ds3q22        ; odd line block
  3411.     bt    count2,0
  3412.     jc    ds3q22        ; odd column block
  3413. ;
  3414.     movzx    ebx,step    ; display step
  3415.     jmp    short ds3q50    ; skip to next block
  3416. ;
  3417. ds3q22:    push    esi
  3418.     call    calc        ; calculate repeat number
  3419.     pop    esi
  3420. ;-------------------------------
  3421. ; genarate color code
  3422. ; in : ax = repeat number
  3423. ;-------------------------------
  3424. ds3q30:    sub    ax,USRCN    ; adjust color code
  3425.     ja    ds3q30
  3426.     add    ax,USRCN    ; AL is effective
  3427. ;-------------------------------
  3428. ; display 1 block
  3429. ; in : al = color code
  3430. ;      esi = block VRAM address
  3431. ;-------------------------------
  3432.     mov    edi,esi        ; set block VRAM address
  3433.     movzx    ebx,step    ; display step
  3434.     mov    dx,bx        ; set block line counter
  3435. ds3q40:    mov    ecx,ebx        ; set block width counter
  3436.     rep    stosb        ; write VRAM by 1 block line
  3437.     sub    edi,ebx        ; rewind VRAM address
  3438.     add    edi,VRAMW    ; next block line VRAM address
  3439.     dec    dx
  3440.     jnz    ds3q40
  3441. ;-------------------------------
  3442. ; move on right block
  3443. ; in : ebx = display step
  3444. ;      esi = block VRAM address
  3445. ;-------------------------------
  3446. ds3q50:    add    esi,ebx        ; next block VRAM address
  3447.     mov    eax,pstep    ; position step
  3448.     add    cura,eax    ; next x position
  3449.     dec    count2        ; check block end of 1 line
  3450.     jnz    ds3q20        ; go tn right block
  3451. ;-------------------------------
  3452. ; move on down block line
  3453. ; in : ebx = display step
  3454. ;      eax = position step
  3455. ;-------------------------------
  3456.     add    esi,bstep    ; next block line VRAM base address
  3457.     add    curb,eax    ; next y position
  3458.     dec    count1        ; check block line end
  3459.     jnz    ds3q10        ; go to next block line
  3460. ;-------------------------------
  3461. ; ending procedure
  3462. ;-------------------------------
  3463.     clc    ; clear carry for completion end
  3464.     ret
  3465. ds3q95:    stc    ; set carry for intteruption end
  3466.     ret
  3467. dsp3q    endp
  3468.  
  3469. ;*******************************
  3470. ; dspadd : display additive
  3471. ;   calculate only C$NULL pixcel
  3472. ;   check A,B button per pixcel
  3473. ;
  3474. ; out: cf = set by interruption
  3475. ;      ax = button state
  3476. ; call: getpad,calc
  3477. ; use: eax,ebx,ecx,edx,esi,edi,ebp
  3478. ;
  3479. dspadd    proc
  3480.     mov    edi,SCRADR
  3481.     mov    eax,posy    ; set y position
  3482.     mov    curb,eax
  3483.     mov    count1,SCRH    ; set screen hight counter
  3484. dsad10:    mov    eax,posx    ; set x position
  3485.     mov    cura,eax
  3486.     mov    count2,SCRW    ; set screen width counter
  3487. dsad20:    cmp    byte ptr es:[edi],0    ; check VRAM state
  3488.     jne    dsad28        ; skip to next pixcel
  3489.     call    getpad        ; get pad state
  3490.     test    ah,ah        ; press A or B button ?
  3491.     jnz    dsad95        ; interruption
  3492.     push    edi
  3493.     call    calc        ; calculate repeat number
  3494.     pop    edi
  3495. dsad22:    sub    ax,USRCN    ; adjust color code
  3496.     ja    dsad22
  3497.     add    ax,USRCN
  3498.     mov    es:[edi],al    ; write VRAM
  3499. dsad28:    inc    edi        ; next VRAM position
  3500.     mov    eax,reso    ; resolution
  3501.     add    cura,eax    ; next x position
  3502.     dec    count2
  3503.     jnz    dsad20
  3504.     add    edi,VRAMW-SCRW    ; new line start address
  3505.     mov    eax,reso    ; resolution
  3506.     add    curb,eax    ; next y position
  3507.     dec    count1
  3508.     jne    dsad10
  3509. ;
  3510.     clc    ; clear carry for completion end
  3511.     ret
  3512. dsad95:    stc    ; set carry for intteruption end
  3513.     ret
  3514. dspadd    endp
  3515.  
  3516. ;*******************************
  3517. ; dspbl : dsplay block line
  3518. ;
  3519. ; in : edi = block start VRAM address
  3520. ;      ebx = display step
  3521. ;      curb = start y position
  3522. ;      reso = resolution
  3523. ; call: dspbk
  3524. ; use: eax,ecx,edx,esi,edi,ebx,ebp
  3525. ;      count1,count2,pstep,cura
  3526. ;
  3527. dspbl    proc
  3528.     mov    esi,edi        ; VRAM address
  3529.     mov    count2,bx    ; save display step
  3530.     mov    ax,SCRW        ; display screen width
  3531.     cwd            ; extend DX:AX
  3532.     div    bx        ; block number in horizon
  3533.     mov    count1,ax    ; set block counter of 1 line
  3534.     imul    ebx,reso
  3535.     mov    pstep,ebx    ; save position step
  3536.     mov    eax,posx    ; set block line x position
  3537.     mov    cura,eax
  3538. ;-------------------------------
  3539. ; display block
  3540. ; in : esi = block VRAM address
  3541. ;-------------------------------
  3542. dsbl10:    call    dspbk        ; display block
  3543. ;-------------------------------
  3544. ; move on right block
  3545. ; in : ebx = display step
  3546. ;      esi = block VRAM address
  3547. ;-------------------------------
  3548.     add    esi,ebx        ; next block VRAM address
  3549.     mov    eax,pstep    ; position step
  3550.     add    cura,eax    ; next x position
  3551.     dec    count1        ; check block end of 1 line
  3552.     jnz    dsbl10        ; go to right block
  3553.     ret
  3554. dspbl    endp
  3555.  
  3556. ;*******************************
  3557. ; dspbc : dsplay block column
  3558. ;
  3559. ; in : edi = block start VRAM address
  3560. ;      ebx = display step
  3561. ;      cura = start x position
  3562. ;      reso = resolution
  3563. ; call: dspbk
  3564. ; use: eax,ecx,edx,esi,edi,ebx,ebp
  3565. ;      count1,count2,pstep,curb
  3566. ;
  3567. dspbc    proc
  3568.     mov    esi,edi        ; VRAM address
  3569.     mov    count2,bx    ; save display step
  3570.     mov    ax,SCRH        ; display screen hight
  3571.     cwd            ; extend DX:AX
  3572.     div    bx        ; block number in vertical
  3573.     mov    count1,ax    ; set block counter of 1 column
  3574.     mov    eax,posy    ; set block line y position
  3575.     mov    curb,eax
  3576.     imul    ebx,reso
  3577.     mov    pstep,ebx    ; save position step
  3578. ;-------------------------------
  3579. ; display block
  3580. ; in : esi = block VRAM address
  3581. ;-------------------------------
  3582. dsbc10:    call    dspbk        ; display block
  3583. ;-------------------------------
  3584. ; move on down block
  3585. ; in : ebx = display step
  3586. ;      edi = next block VRAM address
  3587. ;-------------------------------
  3588.     mov    esi,edi        ; next block VRAM address
  3589.     mov    eax,pstep    ; position step
  3590.     add    curb,eax    ; next y position
  3591.     dec    count1        ; check block end of 1 column
  3592.     jnz    dsbc10        ; go to down block
  3593.     ret
  3594. dspbc    endp
  3595.  
  3596. ;*******************************
  3597. ; dspbk : dsplay block
  3598. ;
  3599. ; in : esi = block VRAM address
  3600. ;      count2 = display step
  3601. ; out: ebx = display step
  3602. ;      esi = block VRAM address
  3603. ;      edi = down block VRAM address
  3604. ; use: eax,ecx,edx,esi,edi,ebx,ebp
  3605. ;
  3606. dspbk    proc
  3607. ;-------------------------------
  3608. ; calculate repeat number
  3609. ;-------------------------------
  3610.     push    esi
  3611.     call    calc        ; calculate repeat number
  3612.     pop    esi
  3613. ;-------------------------------
  3614. ; genarate color code
  3615. ; in : ax = repeat number
  3616. ;-------------------------------
  3617. dsbk20:    sub    ax,USRCN    ; adjust color code
  3618.     ja    dsbk20
  3619.     add    ax,USRCN    ; AL is effective
  3620. ;-------------------------------
  3621. ; display block
  3622. ; in : al = color code
  3623. ;      esi = block VRAM address
  3624. ;-------------------------------
  3625.     mov    edi,esi        ; set block VRAM address
  3626.     movzx    ebx,count2    ; display step
  3627.     mov    dx,bx        ; set block line counter
  3628. dsbk50:    mov    ecx,ebx        ; set block width counter
  3629.     rep    stosb        ; write VRAM by 1 block line
  3630.     sub    edi,ebx        ; rewind VRAM address
  3631.     add    edi,VRAMW    ; next block line VRAM address
  3632.     dec    dx
  3633.     jnz    dsbk50
  3634.     ret
  3635. dspbk    endp
  3636.  
  3637. ;*******************************
  3638. ; calc : calculate repeat number
  3639. ;
  3640. ; in : cura = real part
  3641. ;      curb = imaginary part
  3642. ;      limit = upper limit of number
  3643. ; out: ax = repeat number
  3644. ; use: ecx,edx,esi,edi,ebx,ebp
  3645. ;
  3646. calc    proc
  3647.     movzx    ecx,limit    ; upper limit of number
  3648.     mov    ebx,cura    ; real part
  3649.     mov    ebp,curb    ; imaginary part
  3650.     mov    esi,ebx        ; current x
  3651.     mov    edi,ebp        ; current y
  3652. ;
  3653. calc10:    mov    eax,esi        ; current x
  3654.     imul    eax        ; x^2
  3655.     shrd    eax,edx,24    ; adjust fixed point
  3656.     xchg    eax,esi        ; esi=x^2, eax=x
  3657.     imul    edi        ; x*y
  3658.     shrd    eax,edx,23    ; adjust fixed point and 2 times
  3659.     add    eax,ebp        ; new y = 2xy+b
  3660.     xchg    edi,eax        ; save new y and load old y
  3661.     imul    eax        ; y^2
  3662.     shrd    eax,edx,24    ; adjust fixed point
  3663.     mov    edx,esi        ; x^2
  3664.     add    edx,eax        ; x^2+y^2
  3665.     jz    calc80        ; mandelbrot set or round error
  3666.     cmp    edx,4 shl 24    ; if not |z|<2 then
  3667.     jae    calc90        ; goto end
  3668.     sub    esi,eax        ; x^2-y^2
  3669.     add    esi,ebx        ; new x
  3670.     loop    calc10
  3671. ;
  3672. calc80:    xor    ax,ax        ; over => 0
  3673.     ret
  3674. calc90:    mov    ax,limit
  3675.     sub    ax,cx        ; repeat number
  3676.     ret
  3677. calc    endp
  3678.  
  3679. ;*******************************
  3680. ; calup : calculate up method
  3681. ;     interrupt by A,B button
  3682. ;
  3683. ; in : es = VRAM selector
  3684. ;      posx = position x
  3685. ;      posy = position y
  3686. ;      reso = resolution
  3687. ; out: cf = set by quit end
  3688. ;      ax = pad state
  3689. ;      hbnum = next limit number
  3690. ; call: boxdwn,putdec,getpad
  3691. ; use: all
  3692. ;
  3693. calup    proc
  3694. ;-------------------------------
  3695. ; initialize buffer & screen
  3696. ;-------------------------------
  3697.     mov    edi,buffer    ; calculate buffer address
  3698.     mov    ebx,posy    ; base position y
  3699.     mov    edx,reso    ; resolution
  3700.     mov    ebp,SCRH    ; set screen hight counter
  3701. clup10:    mov    eax,posx    ; set base position x
  3702.     mov    ecx,SCRW    ; set screen width counter
  3703. clup12:    mov    [edi],eax    ; save position x
  3704.     mov    [edi+4],ebx    ; save position y
  3705.     add    edi,8        ; next address
  3706.     add    eax,edx        ; next position x
  3707.     loop    clup12
  3708.     add    ebx,edx        ; next position y
  3709.     dec    ebp
  3710.     jnz    clup10
  3711. ;    
  3712.     mov    esi,offset scrbox    ; screen box pointer
  3713.     mov    al,C$NULL        ; with NULL color
  3714.     call    boxdwn            ; clear box
  3715. ;-------------------------------
  3716. ; preparation for 1 number start
  3717. ;-------------------------------
  3718.     mov    hbnum,0        ; initiarize repeat number
  3719. clup20:    mov    ax,hbnum    ; current number
  3720.     mov    edi,LAUP    ; display position
  3721.     push    esi
  3722.     call    putdec
  3723.     pop    esi
  3724. ;
  3725.     mov    esi,buffer    ; calculate buffer address
  3726.     mov    edi,reso    ; set resolution
  3727.     mov    ebp,posy    ; start position y
  3728.     mov    count1,SCRW    ; set higth counter
  3729. clup30:    mov    ebx,posx    ; start position x
  3730.     mov    count2,SCRW    ; set width counter
  3731. clup40:    cmp    dword ptr [esi],0    ; check completed
  3732.     jne    clup50
  3733.     cmp    dword ptr [esi+4],0
  3734.     je    clup70        ; skip
  3735. ;-------------------------------
  3736. ; calculate 1 limit step
  3737. ; in : ebx = a
  3738. ;      ebp = b
  3739. ;      esi = x,y data pointer
  3740. ;-------------------------------
  3741. clup50:    mov    eax,[esi]    ; current x
  3742.     imul    eax        ; x^2
  3743.     shrd    eax,edx,24    ; adjust fixed point
  3744.     mov    ecx,eax        ; save x^2
  3745. ;
  3746.     mov    eax,[esi+4]    ; current y
  3747.     imul    dword ptr [esi]    ; x*y
  3748.     shrd    eax,edx,23    ; adjust fixed point and 2 times
  3749.     add    eax,ebp        ; 2x*y+b
  3750. ;
  3751.     xchg    [esi+4],eax    ; load eax=y and save new y=2x*y+b
  3752.     imul    eax        ; y^2
  3753.     shrd    eax,edx,24    ; adjust fixed point
  3754. ;
  3755.     mov    edx,ecx        ; x^2
  3756.     add    edx,eax        ; x^2+y^2
  3757.     jz    clup84        ; mandelbrot element
  3758.     cmp    edx,4 shl 24    ; if not |z|<2 then
  3759.     jae    clup80        ; goto dispaly pixcel
  3760. ;
  3761.     sub    ecx,eax        ; x^2-y^2
  3762.     add    ecx,ebx        ; x^2-y^2+a
  3763.     mov    [esi],ecx    ; save new x
  3764. ;-------------------------------
  3765. ; repeat end check
  3766. ;-------------------------------
  3767. clup70:    add    esi,8        ; next (x,y) data pointer
  3768.     add    ebx,edi        ; left pixcel position a
  3769.     dec    count2        ; width counter down
  3770.     jnz    clup40        ; go to left pixcel
  3771.     add    ebp,edi        ; next line position b
  3772.     dec    count1        ; hight counter down
  3773.     jnz    clup30        ; go to next line
  3774. ;
  3775.     inc    hbnum        ; repeat number up
  3776.     jz    clup90        ; limit over
  3777.     call    getpad        ; get pad state
  3778.     test    ah,ah        ; press A or B button ?
  3779.     jz    clup20        ; no go to next repeat number
  3780. ;-------------------------------
  3781. ; ending
  3782. ;-------------------------------
  3783.     stc    ; quit end
  3784. clup90:    mov    curstat,DS$FULL    ; display completion
  3785.     mov    step,0
  3786.     ret
  3787. ;-------------------------------
  3788. ; display pixcel
  3789. ; in : edi = VRAM address
  3790. ;-------------------------------
  3791. clup80:    mov    cx,hbnum    ; repeat number
  3792. clup82:    sub    cx,USRCN    ; adjust color code
  3793.     ja    clup82
  3794.     add    cx,USRCN
  3795.     mov    ax,SCRY+SCRH
  3796.     sub    ax,count1
  3797.     cwde
  3798.     imul    eax,VRAMW
  3799.     add    eax,SCRX+SCRW
  3800.     movzx    edx,count2
  3801.     sub    eax,edx
  3802.     mov    es:[eax],cl    ; write VRAM
  3803. clup84:    mov    dword ptr [esi],0    ; set complete flag
  3804.     mov    dword ptr [esi+4],0
  3805.     jmp    clup70
  3806. calup    endp
  3807.  
  3808. ;*******************************
  3809. ; putdec : put decimal number
  3810. ;      within 5 column
  3811. ;
  3812. ; in : ax = binary
  3813. ;      edi = display VAM base address
  3814. ;      numwid = display width of number
  3815. ; call: bn2dec,dspank
  3816. ; use: ax,ecx,dx,ebx,esi,edi
  3817. ;      work1
  3818. ;
  3819. putdec    proc
  3820.     mov    ebx,offset work1+2
  3821.     movzx    ecx,numwid        ; display width
  3822.     mov    [ebx-2],cx
  3823.     call    bn2dec
  3824.     mov    esi,offset work1    ; string data address
  3825.     call    dspank
  3826.     ret
  3827. putdec    endp
  3828.  
  3829. ;*******************************
  3830. ; putfp : put fixed point
  3831. ;    within 10 column
  3832. ;
  3833. ; in : eax = fixed point
  3834. ;      edi = base VRAM address
  3835. ; call: bn4dec,dspank
  3836. ; use: all
  3837. ;      work1
  3838. ;
  3839. putfp    proc
  3840.     mov    ebx,offset work1    ; destination address
  3841.     call    bn4dec            ; convert to decimal
  3842.     mov    esi,offset work1    ; string data address
  3843.     movzx    ecx,word ptr [esi]    ; effective lenght
  3844.     mov    al,20h            ; SPAC
  3845. putfp1:    mov    [esi+ecx+2],al
  3846.     inc    ecx
  3847.     cmp    ecx,10
  3848.     jb    putfp1
  3849.     mov    word ptr [esi],10
  3850.     call    dspank            ; display ANK strings
  3851.     ret
  3852. putfp    endp
  3853.  
  3854. ;*******************************
  3855. ; bn2dec : 2 binary to decimal
  3856. ;
  3857. ; in : ax = unsigned binary
  3858. ;      ecx = column width
  3859. ;      ebx = destination address
  3860. ; use: ax,ecx,dx
  3861. ;
  3862. bn2dec    proc
  3863.     push    si
  3864.     mov    si,10
  3865. bn2de1:    xor    dx,dx
  3866.     div    si
  3867.     add    dl,'0'
  3868.     mov    [ebx+ecx-1],dl    ; save digit
  3869.     test    ax,ax        ; check end
  3870.     loopnz    bn2de1
  3871. ;
  3872. bn2de4:    jcxz    bn2de9
  3873.     mov    byte ptr [ebx+ecx-1],20h    ; sapce padding
  3874.     dec    ecx
  3875.     jmp    bn2de4
  3876. bn2de9:    pop    si
  3877.     ret
  3878. bn2dec    endp
  3879.  
  3880. ;*******************************
  3881. ; bn4dec : signed 4 byte fixed
  3882. ;   point binary to decimal
  3883. ;
  3884. ; in : eax = binary
  3885. ;      ebx = destination address
  3886. ;      cs = ds
  3887. ; out: ebx = fixed decimal
  3888. ;         0(2) byte length n+3
  3889. ;         2(1) sign ('-' or ' ')
  3890. ;         3(1) integer part
  3891. ;         4(1) decimal point
  3892. ;         5(n) decimal part
  3893. ; use: eax,ecx,edx,ebx
  3894. ;
  3895. bn4de0    dd    10000000
  3896.     dd    1000000
  3897.     dd    100000
  3898.     dd    10000
  3899.     dd    1000
  3900.     dd    100
  3901.     dd    10
  3902.     dd    1
  3903. ;
  3904. bn4dec    proc
  3905.     push    esi
  3906.     push    ebx
  3907.     add    ebx,2        ; skip length area
  3908.     mov    byte ptr [ebx],' '
  3909.     test    eax,eax
  3910.     jns    bn4de1
  3911.     mov    byte ptr [ebx],'-'
  3912.     neg    eax
  3913. bn4de1:    inc    ebx
  3914. ;
  3915.     mov    esi,offset bn4de0
  3916.     mul    dword ptr [esi]    ; significant figure
  3917.     shrd    eax,edx,24
  3918.     adc    eax,0        ; round
  3919. ;
  3920.     xor    edx,edx        ; integer part
  3921.     div    dword ptr [esi]
  3922.     add    al,'0'
  3923.     mov    ah,'.'
  3924.     mov    [ebx],ax
  3925.     add    esi,4
  3926.     add    ebx,2
  3927.     mov    eax,edx
  3928. ;
  3929.     mov    ecx,7
  3930. bn4de2:    xor    edx,edx        ; extend dividend EDX:EAX
  3931.     div    dword ptr [esi]
  3932.     add    al,'0'
  3933.     mov    [ebx],al    ; save quotient
  3934.     add    esi,4        ; next divisor address
  3935.     inc    ebx        ; next save address
  3936.     mov    eax,edx        ; set new dividend
  3937.     test    eax,eax
  3938.     loopnz    bn4de2
  3939. ;
  3940.     pop    eax        ; destination address
  3941.     sub    ebx,eax
  3942.     sub    bx,2
  3943.     mov    [eax],bx    ; save length
  3944.     pop    esi
  3945.     ret
  3946. bn4dec    endp
  3947.  
  3948. ;*******************************
  3949. ; setdp : set display pallets
  3950. ;         0 to USRCN
  3951. ;
  3952. ; in : palbuf = pallet data buffer
  3953. ; call: waitv,setpal
  3954. ; use: all & work1
  3955. ;
  3956. setdp    proc
  3957.     mov    edi,offset palbuf    ; pallet data buffer
  3958.     mov    esi,offset work1    ; pallet packet
  3959.     mov    byte ptr [esi],0    ; initialize pallet number
  3960.     mov    bx,PALSBN        ; set pallet block counter
  3961.     mov    ecx,PALSBR        ; set rest pallet number
  3962. setdp1:    call    waitv            ; wait VSYNC
  3963. setdp2:    mov    eax,[edi]        ; level data + 1
  3964.     mov    [esi+1],eax        ; set level data
  3965.     call    setpal            ; set pallet code
  3966.     add    edi,3            ; next pallet address
  3967.     inc    byte ptr [esi]        ; next pallet number
  3968.     loop    setdp2
  3969.     mov    ecx,PALSBS        ; set pallet block size
  3970.     dec    bx
  3971.     jnz    setdp1
  3972.     ret
  3973. setdp    endp
  3974.  
  3975. ;*******************************
  3976. ; setpal : set pallet data
  3977. ;
  3978. ; in : (ds:esi) = data address
  3979. ; use: dx
  3980. ;
  3981. setpal    proc
  3982.     push    esi
  3983.     mov    dx,0FD90h    ; pallet code
  3984.     outsb
  3985.     mov    dx,0FD92h    ; blue pallet data
  3986.     outsb
  3987.     mov    dx,0FD94h    ; red pallet data
  3988.     outsb
  3989.     mov    dx,0FD96h    ; green pallet data
  3990.     outsb
  3991.     pop    esi
  3992.     ret
  3993. setpal    endp
  3994.  
  3995. ;*******************************
  3996. ; dspank : display ank
  3997. ;    string color is C$DARK
  3998. ;    backgraund is C$PANEL
  3999. ;
  4000. ; in : esi = string address
  4001. ;      edi = base VRAM address
  4002. ;         0(2) byte size (n)
  4003. ;         2(n) byte string
  4004. ;      es = VRAM selector
  4005. ; use: none
  4006. ;
  4007. dspank    proc
  4008.     push    fs
  4009.     push    ebp
  4010.     push    esi
  4011.     push    edi
  4012.     push    edx
  4013.     push    ecx
  4014.     push    ebx
  4015.     push    eax
  4016. ;
  4017.     lfs    ebx,pword ptr ss:[ankfnt]
  4018.     lodsw
  4019.     movzx    ecx,ax        ; length counter
  4020. dpank1:    lodsb            ; ANK code
  4021.     call    dpankA        ; character display
  4022.     add    edi,8        ; next character address
  4023.     loop    dpank1
  4024. ;
  4025.     pop    eax
  4026.     pop    ebx
  4027.     pop    ecx
  4028.     pop    edx
  4029.     pop    edi
  4030.     pop    esi
  4031.     pop    ebp
  4032.     pop    fs
  4033.     ret
  4034. ;------------------------------
  4035. ; in : al = ANK code
  4036. ;      fs:ebx = font ROM address
  4037. ;      es:edi = base VRAM address
  4038. ; use: ax
  4039. ;
  4040. dpankA    proc
  4041.     push    edi
  4042.     push    ecx
  4043.     xor    ah,ah
  4044.     shl    ax,4
  4045.     add    ax,15
  4046.     movzx    ebp,ax        ; destination base offset
  4047.     mov    dx,16        ; hight counter
  4048. dpakA1:    mov    ah,fs:[ebx+ebp]
  4049.     mov    ecx,8
  4050. dpakA2:    mov    al,C$DARK    ; number color
  4051.     shl    ah,1
  4052.     jc    dpakA3
  4053.     mov    al,C$PANEL    ; backgraund color fixed
  4054. dpakA3:    stosb
  4055.     loop    dpakA2
  4056.     dec    ebp
  4057.     sub    edi,VRAMW+8
  4058.     dec    dx
  4059.     jnz    dpakA1
  4060.     pop    ecx
  4061.     pop    edi
  4062.     ret
  4063. dpankA    endp
  4064. dspank    endp
  4065.  
  4066. ;*******************************
  4067. ; getstr : get string from keybord
  4068. ;     with echo
  4069. ;     only 0-9,A-Z
  4070. ;     control code BS,CR,ESC
  4071. ;
  4072. ; in : (ds:esi) = string address
  4073. ;          0(2) position x
  4074. ;          2(2) position y
  4075. ;       cx = maximum string length
  4076. ;       es = VRAM selector
  4077. ;       fs = TOWNS BIOS selector
  4078. ; out: (ds:esi)
  4079. ;          4(2) inputed string length
  4080. ; call: waitp,getpad
  4081. ; use: eax,ebx,ecx,edx
  4082. ;
  4083. getstr    proc
  4084.     push    edi
  4085. ;-------------------------------
  4086. ; initialize
  4087. ;-------------------------------
  4088.     mov    ax,0600h    ; clear keybord buffer
  4089.     int    90h
  4090.     xor    ax,ax        ; wait no press state
  4091.     push    cx
  4092.     call    waitp
  4093.     pop    cx
  4094.     mov    word ptr [esi+4],0    ; clear counter
  4095. ;-------------------------------
  4096. ; get key or button & analyze it
  4097. ;-------------------------------
  4098. gtst10:    mov    ax,0901h    ; read charactor without waiting
  4099.     int    90h
  4100.     test    ah,ah        ; go well ?
  4101.     jnz    gtst12        ; read error
  4102.     cmp    dh,0FFh        ; exist input charactor ?
  4103.     jne    gtst14        ; go to analyze
  4104. ;
  4105. gtst12:    call    getpad        ; get pad state
  4106.     test    ah,P$TRIG1    ; A button
  4107.     jnz    gtst99        ; input end
  4108.     test    ah,P$TRIG2    ; B button
  4109.     jnz    gtst90        ; quit
  4110.     jmp    gtst10
  4111. ;
  4112. gtst14:    cmp    dl,1BH        ; ESC
  4113.     je    gtst90        ; quit
  4114.     cmp    dl,0Dh
  4115.     je    gtst99        ; input end
  4116.     cmp    dl,08h        ; CTRL+H
  4117.     je    gtst40        ; back space
  4118.     cmp    dl,'0'
  4119.     jb    gtst10        ; invalid
  4120.     cmp    dl,'9'
  4121.     jbe    gtst22        ; number
  4122.     cmp    dl,'A'
  4123.     jb    gtst10        ; invalid
  4124.     cmp    dl,'Z'
  4125.     jbe    gtst22        ; capital
  4126.     cmp    dl,'a'
  4127.     jb    gtst10        ; invalid
  4128.     cmp    dl,'z'
  4129.     ja    gtst10        ; invalid
  4130. ;-------------------------------
  4131. ; save and display
  4132. ; in : esi = string address
  4133. ;      cx = maximum length
  4134. ;-------------------------------
  4135. gtst20:    add    dl,'A'-'a'    ; capitalize
  4136. gtst22:    movzx    eax,word ptr [esi+4]    ; current length
  4137.     cmp    ax,cx        ; check max length
  4138.     jae    gtst10        ; invalid
  4139.     inc    ax        ; renew length
  4140.     mov    [esi+4],ax
  4141.     mov    byte ptr [esi+eax+5],dl    ; save charactor
  4142.     mov    edi,offset egbwork
  4143.     mov    ax,6001h    ; display ASCII string
  4144.     call    pword ptr fs:[20h]
  4145.     jmp    gtst10
  4146. ;-------------------------------
  4147. ; back space
  4148. ; in : esi = string address
  4149. ;-------------------------------
  4150. gtst40:    movzx    eax,word ptr [esi+4]
  4151.     test    ax,ax
  4152.     jz    gtst10        ; invalid
  4153.     dec    ax
  4154.     mov    [esi+4],ax
  4155. ;
  4156.     push    ecx
  4157.     shl    ax,3        ; string pixcel width
  4158.     add    ax,[esi]    ; clear start x position
  4159.     movzx    edi,ax
  4160.     movzx    eax,word ptr [esi+2]
  4161.     imul    eax,VRAMW
  4162.     add    edi,eax        ; clear start address
  4163.     mov    ecx,16
  4164.     mov    eax,C$PANEL+(C$PANEL shl 8)+(C$PANEL shl 16)+(C$PANEL shl 24)
  4165. gtst42:    mov    es:[edi],eax
  4166.     mov    es:[edi+4],eax
  4167.     sub    edi,VRAMW
  4168.     loop    gtst42
  4169.     pop    ecx
  4170.     jmp    gtst10
  4171. ;-------------------------------
  4172. ; input end
  4173. ;-------------------------------
  4174. gtst90:    mov    word ptr [esi+4],0    ; cancel string
  4175. gtst99:    pop    edi
  4176.     ret
  4177. getstr    endp
  4178. code    ends
  4179.  
  4180. stack    segment stack use32 rw
  4181. pathbuf    db    80h dup(?)    ; for pathlist
  4182. idata    db    SCRW*SCRH/2 dup(?)    ; for initial screen data
  4183. ankfnt    dd    ?    ; ANK font offset
  4184.     dw    ?    ; ANK font selector
  4185. palbuf    db    (USRCN+1)*3 dup(?)    ; pallet data buffer
  4186.     db    ?    ; dummy
  4187. palbak    db    (USRCN+1)*3 dup(?)    ; pallet data backup buffer
  4188.     db    ?    ; dummy
  4189. work1    db    80 dup(?)    ; public work 1
  4190. egbwork    db    EGBSIZ dup(?)    ; EGB work area
  4191.     db    256*256 dup(?)    ; stack for EGB
  4192.     db    6*1024 dup (?)    ; stack area
  4193. stack    ends
  4194.  
  4195.     end entry
  4196.