Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Address Bus:
  2. //0 - 2048 ... Console screen
  3. //2048 - 56 ... Keyboard
  4. //2104 - 20971520 ... Memory
  5.  
  6. jmp codestart;
  7. define screen,65536;
  8. define keyboard,67584;
  9. define floppy,67640;
  10.  
  11. inputbuffer: alloc 30;
  12. bufferpointer: db 0;
  13. commandline: db 0;
  14.  
  15. commandchar: db '>';
  16.  
  17. txtdiskinfo1: db 'You have ',0;
  18. txtdiskinfo2: db 'bytes total.',0;
  19.  
  20. MemoryErrorFlag: db 0;
  21. MemoryErrorCounter: db 0;
  22.  
  23. InterruptHandler:
  24.  alloc 1024;
  25.  
  26. MemoryError:
  27.  mov #MemoryErrorFlag,1;
  28.  inc #MemoryErrorCounter;
  29. iret;
  30.  
  31. Wait: //001 - ecx = time in seconds |
  32.     push eax;
  33.     push ebx;
  34.  
  35.     timer ebx;
  36.     Loop_001:
  37.         timer eax;
  38.         sub eax,ebx;
  39.         cmp eax,ecx;
  40.     jne Loop_001;
  41.  
  42.     pop ebx;
  43.     pop eax;
  44. ret
  45.  
  46. WriteString: //002 - esi = string; edi = CS-X/Y; ecx = color(RGBRGBX) |
  47.     push esi;
  48.     push edi;
  49.     push es;
  50.  push eax;
  51.  
  52.     mov es,screen;
  53.  
  54.     Loop_002:
  55.         cmp #esi,0;
  56.         je End_002;
  57.   cmp #esi,13;
  58.   je Newline_002;
  59.         mov es:#edi,#esi;
  60.         inc edi;
  61.         mov es:#edi,ecx;
  62.         inc edi;
  63.         inc esi;
  64.     jmp Loop_002;
  65.  
  66. Newline_002:
  67.   push ecx;
  68.   push edx;
  69.   inc #commandline;
  70.   cmp #commandline,16;
  71.   cg ScrollScreen;
  72.   mov edx,#commandline;
  73.   mov ecx,0;
  74.   call XYToCS;
  75.   mov edi,eax;
  76.   inc esi;
  77.   pop edx;
  78.   pop ecx;
  79. jmp Loop_002;
  80.  
  81. End_002:
  82.  pop eax;
  83.     pop es;
  84.     pop edi;
  85.     pop esi;
  86. ret
  87.  
  88. ReadKey: //003 - | eax = pressed key
  89.     push es;
  90.     mov es,keyboard;
  91.  mov eax,0;
  92.     cmp es:#0,0;
  93.     je End_003; //no keys in buffer, exit
  94.     mov eax,es:#1;
  95.     mov es:#1,eax;
  96.  
  97. End_003:
  98.     pop es;
  99. ret
  100.  
  101. WaitForKey: //004 - | eax = Key
  102.     push es;
  103.     mov es,keyboard;
  104.     Loop_004:
  105.         cmp es:#0,0;
  106.         jne Next_004;
  107.         idle;
  108.     jmp Loop_004;
  109.     Next_004:
  110.         mov eax,es:#1;
  111.         mov es:#1,eax;
  112.     pop es;
  113. ret
  114.  
  115. strcmp: //005 - esi = string1; edi = string2 | eax = same?
  116.     Loop_005:
  117.         cmp #esi,0;
  118.         je A_0_005;
  119.         cmp #edi,0;
  120.         je unsame;
  121.         cmp #esi,#edi;
  122.         jne unsame;
  123.         inc esi;
  124.         inc edi;
  125.     jmp Loop_005;
  126.  
  127.     A_0_005:
  128.     cmp #edi,0;
  129.     jne unsame;
  130.     mov eax,1;
  131.     jmp End_005;
  132.  
  133.     unsame:
  134.     mov eax,0
  135. End_005:
  136. ret
  137.  
  138. XYToCS: //006 - ecx = X; edx = Y | eax = CS
  139.     mov eax,edx;
  140.     mul eax,30;
  141.     add eax,ecx;
  142.  mul eax,2;
  143. ret
  144.  
  145. WriteNum: //007 - esi = number; edi = position; ecx = color |
  146.     push esi;
  147.     push es;
  148.  push eax;
  149.  push ebx;
  150.  push edi;
  151.  push edx;
  152.  
  153.     mov es,screen;
  154.  
  155.  mov eax,esi;
  156.  call GetNumberLength;
  157.  mov eax,ebx;
  158.  
  159.  Loop_007:
  160.   mov edx,10;
  161.   fpwr edx,eax;
  162.   mov ebx,esi;
  163.   mod ebx,edx;
  164.   div edx,10;
  165.   div ebx,edx;
  166.   fint ebx;
  167.  
  168.     add ebx,48;
  169.      mov es:#edi,ebx;
  170.     inc edi;
  171.      mov es:#edi,ecx;
  172.     inc edi;
  173.   cmp eax,1;
  174.   je End_007;
  175.   dec eax;
  176.  jmp Loop_007;
  177.  
  178.  End_007:
  179.  pop edx;
  180.  pop edi;
  181.  pop ebx;
  182.  pop eax;
  183.     pop es;
  184.     pop esi;
  185. ret
  186.  
  187. ClearScreen: //008 - |
  188.     push es;
  189.     mov es,screen;
  190.    
  191.     mov es:#2041,1;
  192.     idle;
  193.  
  194.  mov #commandline,0;
  195.  
  196.     pop es;
  197. ret
  198.  
  199. WriteByte: //009 - esi = byte; edi = position; ecx = color |
  200.     push es;
  201.     mov es,screen;
  202.  
  203.     mov es:#edi,esi;
  204.     inc edi;
  205.     mov es:#edi,ecx;
  206.     dec edi;
  207.  
  208.     pop es;
  209. ret
  210.  
  211. space_010: db ' ';
  212.  
  213. ProcessKey: //010 - eax = key |
  214.     push ebx;
  215.  
  216.     cmp eax,154; //SHIFT
  217.     je End_010;
  218.     cmp eax,158; //CTRL
  219.     je End_010;
  220.     cmp eax,144; //CAPS
  221.     je End_010;
  222.     cmp eax,160; //WINDOWS
  223.     je End_010;
  224.     cmp eax,9; //TAB
  225.     je End_010;
  226.     cmp eax,127; //BACKSPACE
  227.     je backspace_010;
  228.     cmp eax,162; //the thing next to the right windows key
  229.     je End_010;
  230.     cmp eax,13; //Enter Key
  231.     je enter_010;
  232.  cmp eax,13;
  233.     je End_010;
  234.  
  235.  cmp #bufferpointer,29;
  236.  je End_010;
  237.     mov ebx,inputbuffer;
  238.     add ebx,#bufferpointer;
  239.     mov #ebx,eax;
  240.     inc #bufferpointer;
  241.  jmp End_010;
  242.  
  243. backspace_010:
  244.  cmp #bufferpointer,0;
  245.  je End_010;
  246.  mov ebx,inputbuffer;
  247.  dec #bufferpointer;
  248.  add ebx,#bufferpointer;
  249.  mov #ebx,0;
  250.  mov esi,#space_010;
  251.  mov ecx,#bufferpointer;
  252.  inc ecx;
  253.  mov edx,#commandline;
  254.  call XYToCS;
  255.  mov edi,eax;
  256.  mov ecx,000999;
  257.  call WriteByte;
  258.  jmp End_010;
  259.  
  260. enter_010:
  261. ce ProcessInput;
  262. jmp End_010;
  263.  
  264. End_010:
  265. pop ebx;
  266. ret
  267.  
  268. strlen: //011 - esi = string | eax = length
  269.     push esi;
  270.     mov eax,0;
  271.     Loop_011:
  272.         cmp #esi,0;
  273.         je End_011;
  274.         inc esi;
  275.         inc eax;
  276.     jmp Loop_011;
  277. End_011:
  278. pop esi;
  279. ret
  280.  
  281. scmdhelp_012: db 'help',0;
  282. scmdclear_012: db 'clear',0;
  283. scmddiskinfo_012: db 'diskinfo',0;
  284. scmdformat_012: db 'format',0;
  285.  
  286. txtHelp_012: db 'The current commands are:',13;
  287. db 'help  -  displays this help',13;
  288. db 'clear  -  clears the screen',13;
  289. db 'diskinfo - disk information',13;
  290. db 'format - format the disk',13,0;
  291.  
  292. txtUnknownCommand_012: db 'The command could not be found',0;
  293.  
  294. txtFormat1_012: db 'Formatting disk...',0;
  295. txtFormat2_012: db 'Disk formatted.',0;
  296.  
  297. ProcessInput: //012 - |
  298.     push esi;
  299.     push eax;
  300.     push edi;
  301.     push ecx;
  302.     push edx;
  303.  
  304.     mov #bufferpointer,0;
  305.     mov esi,inputbuffer;
  306.  
  307.  //help
  308.     mov edi,scmdhelp_012;
  309.     call strcmp;
  310.     cmp eax,1;
  311.     je cmdhelp_012;
  312.  
  313.  //clear
  314.     mov edi,scmdclear_012;
  315.     call strcmp;
  316.     cmp eax,1;
  317.     je cmdclear_012;
  318.  
  319.  //diskinfo
  320.  mov edi,scmddiskinfo_012;
  321.  call strcmp;
  322.  cmp eax,1;
  323.  je cmddiskinfo_012;
  324.  
  325.  //format
  326.  mov edi,scmdformat_012;
  327.  call strcmp;
  328.  cmp eax,1;
  329.  je cmdformat_012;
  330.  
  331.  //unknown command
  332.  inc #commandline;
  333.  cmp #commandline,16;
  334.  cg ScrollScreen;
  335.  mov esi,txtUnknownCommand_012;
  336.  mov ecx,0;
  337.  mov edx,#commandline;
  338.  call XYToCS;
  339.  mov edi,eax;
  340.  mov ecx,000999;
  341.  call WriteString;
  342.  inc #commandline;
  343.  cmp #commandline,16;
  344.  cg ScrollScreen;
  345.  jmp End_012;
  346.  
  347. cmdclear_012:
  348.  call ClearScreen;
  349.  jmp End_012;
  350.  
  351. cmdhelp_012:
  352.  inc #commandline;
  353.  cmp #commandline,16;
  354.  cg ScrollScreen;
  355.     mov esi,txtHelp_012;
  356.  mov ecx,0;
  357.  mov edx,#commandline;
  358.  call XYToCS;
  359.     mov edi,eax;
  360.     mov ecx,000999;
  361.     call WriteString;
  362. jmp End_012;
  363.  
  364. cmddiskinfo_012:
  365.  inc #commandline;
  366.  cmp #commandline,16;
  367.  cg ScrollScreen;
  368.  mov ecx,0;
  369.  mov edx,#commandline;
  370.  call XYToCS;
  371.  mov edi,eax;
  372.  mov esi,txtdiskinfo1;
  373.  mov ecx,000999;
  374.  call WriteString;
  375.  
  376.  add edi,18;
  377.  call GetFloppySize;
  378.  mov esi,eax;
  379.  call WriteNum;
  380.  
  381.  push ebx;
  382.  mov eax,esi;
  383.  call GetNumberLength;
  384.  mov ecx,ebx;
  385.  pop ebx;
  386.  inc ecx;
  387.  mul ecx,2;
  388.  add edi,ecx;
  389.  
  390.  mov esi,txtdiskinfo2;
  391.  mov ecx,000999;
  392.  call WriteString;
  393.  inc #commandline;
  394. jmp End_012;
  395.  
  396. cmdformat_012:
  397.  inc #commandline;
  398.  cmp #commandline,16;
  399.  cg ScrollScreen;
  400.  mov ecx,0;
  401.  mov edx,#commandline;
  402.  call XYToCS;
  403.  mov esi,txtFormat1_012;
  404.  mov edi,eax;
  405.  mov ecx,000999;
  406.  call WriteString;
  407.  inc #commandline;
  408.  
  409.  call FormatDisc;
  410.  
  411.  mov ecx,0;
  412.  mov edx,#commandline;
  413.  call XYToCS;
  414.  mov esi,txtFormat2_012;
  415.  mov edi,eax;
  416.  mov ecx,000999;
  417.  call WriteString;
  418.  inc #commandline;
  419. jmp End_012;
  420.  
  421. End_012:
  422.     pop edx;
  423.     pop ecx;
  424.     pop edi;
  425.     pop eax;
  426.     pop esi;
  427.  call ClearInputBuffer;
  428.  call WriteCommandChar;
  429. ret
  430.  
  431. ClearInputBuffer: //013 - |
  432.  push ecx;
  433.  push esi;
  434.  mov ecx,29;
  435.  Loop_013:
  436.   mov #bufferpointer,29;
  437.   sub #bufferpointer,ecx;
  438.   mov esi,inputbuffer;
  439.   add esi,#bufferpointer;
  440.   mov #esi,0;
  441.  loop Loop_013;
  442.  
  443.  mov #bufferpointer,0;
  444.  pop esi;
  445.  pop ecx;
  446. ret
  447.  
  448. ScrollScreen: //014 - |
  449.  push es;
  450.  mov es,screen;
  451.  mov es:#2038,1;
  452.  dec #commandline;
  453.  pop es;
  454. ret
  455.  
  456. GetFloppySize: //015 - | eax = size
  457.  push es;
  458.  push ebx;
  459.  push ecx;
  460.  push edx;
  461.  
  462.  mov es,floppy;
  463.  mov ebx,262144; //stepsize
  464.  mov eax,0; //output
  465.  mov ecx,0; //the byte to be checked
  466.  mov edx,0;
  467.  mov #MemoryErrorFlag,0;
  468.  mov es:#ecx,5;
  469.  cmp es:#ecx,5;
  470.  jne Null_015;
  471.  cmp #MemoryErrorFlag,1;
  472.  je Null_015;
  473.  mov es:#ecx,0;
  474.  add ecx,ebx;
  475.  
  476.  Loop_015:
  477.   mov #MemoryErrorFlag,0;
  478.   mov es:#ecx,5;
  479.   cmp es:#ecx,5;
  480.   jne NP_015;
  481.   cmp #MemoryErrorFlag,1;
  482.   je NP_015;
  483.   mov es:#ecx,0;
  484.   cmp ebx,1;
  485.   je End_P_015;
  486.   add ecx,ebx;
  487.  
  488.  jmp Loop_015;
  489.  
  490.  NP_015:
  491.   mov #MemoryErrorFlag,0;
  492.   cmp ebx,1;
  493.   je End_NP_015;
  494.   div ebx,2;
  495.   sub ecx,ebx;
  496.   jmp Loop_015;
  497.  
  498. End_P_015:
  499.  mov eax,ecx;
  500.  inc eax;
  501.  jmp End_015;
  502.  
  503. End_NP_015:
  504.  mov eax,ecx;
  505.  jmp End_015;
  506.  
  507. Null_015:
  508.  mov eax,0;
  509.  mov #MemoryErrorFlag,0;
  510.  jmp End_015;
  511.  
  512. End_015:
  513.  pop edx;
  514.  pop ecx;
  515.  pop ebx;
  516.  pop es;
  517. ret
  518.  
  519. CSToXY: //016 - eax = CS | ecx = X; edx = Y
  520.  mov ecx,eax;
  521.  mod ecx,30;
  522.  mov edx,eax;
  523.  sub edx,ecx;
  524.  div eax,30;
  525. ret
  526.  
  527. WriteCommandChar: //017 - |
  528. mov esi,#commandchar;
  529. mov ecx,0;
  530. mov edx,#commandline;
  531. call XYToCS;
  532. mov edi,eax;
  533. mov ecx,999;
  534. call WriteByte;
  535. ret
  536.  
  537. WriteInputBuffer: //018 - |
  538.  mov esi,inputbuffer;
  539.  mov ecx,1;
  540.  mov edx,#commandline;
  541.  call XYToCS;
  542.  mov edi,eax;
  543.  mov ecx,000999;
  544.  call WriteString;
  545. ret
  546.  
  547. GetNumberLength: //019 - eax = number | ebx = length
  548.  cmp eax,0;
  549.  je Null_019;
  550.  
  551.  flog10 ebx,eax;
  552.  fint ebx;
  553.  inc ebx;
  554.  jmp End_019;
  555.  
  556.  Null_019:
  557.   mov ebx,1;
  558.  jmp End_019;
  559.  
  560.  End_019:
  561. ret
  562.  
  563. Disc_020:
  564.     db 0,0,0,'Xandaros',512,0; //last 0: FAT_Size
  565.  
  566. FormatDisc: //020 - |
  567.  push eax;
  568.  push esi;
  569.  push edi;
  570.  push ecx;
  571.  
  572.  call GetFloppySize; //EAX = Gg
  573.  sub eax,8205;
  574.  div eax,513;
  575.  fint eax; //EAX = FAT_SIZE
  576.  mov edi,Disc_020;
  577.  add edi,12;
  578.  mov #edi,eax; //put FAT_Size in
  579.  mov edi,floppy;
  580.  mov esi,Disc_020;
  581.  mcopy 13;
  582.  
  583.  mov ecx,eax;
  584.  mul ecx,17;
  585.  inc ecx;
  586.  Loop_020:
  587.   mov edi,floppy;
  588.   add edi,12;
  589.   add edi,ecx;
  590.   mov #edi,0;
  591.  loop Loop_020;
  592.  
  593.  pop ecx;
  594.  pop edi;
  595.  pop esi;
  596.  pop eax;
  597. ret
  598.  
  599. strmid: //021 - esi = string; edi = output-string; eax = start; ebx = length |
  600.  push ecx;
  601.  push esi;
  602.  
  603.  add esi,eax;
  604.  dec esi;
  605.  mov ecx,ebx;
  606.  Loop_021:
  607.   mov #edi,#esi;
  608.   inc edi;
  609.   inc esi;
  610.  loop Loop_021;
  611.  mov #edi,0;
  612.  
  613.  pop esi;
  614.  pop ecx;
  615. ret
  616.  
  617. MakeFile: //022 - esi = filename(string; length MUST be 8, not zero-terminated); edi = extension (length 3, not zero-terminated) |
  618.  push edx;
  619.  push ecx;
  620.  push eax;
  621.  push es;
  622.  
  623.  mov es,floppy; //Floppy
  624.  add es,13; //RootDirectory
  625.  mov ecx,512;
  626.  Loop1_022:
  627.   mov edx,512;
  628.   sub edx,ecx; //EDX = 512 - ECX
  629.   mul edx,16; //Each RootDirectory entry has 16 byte
  630.   cmp es:#edx,0; //If the first character of the file name is 0,
  631.   je Found_022; //We found some space
  632.  loop Loop1_022;
  633.  je End_022; //Otherwise all 512 files are taken
  634.  
  635.  Found_022:
  636.   mov port1,1;
  637.   mov ecx,8;
  638.   Loop2_022:
  639.    mov eax,esi;
  640.    add eax,8;
  641.    sub eax,ecx;
  642.    mov es:#edx,#eax;
  643.    inc edx;
  644.   loop Loop2_022;
  645.  
  646.   mov ecx,3;
  647.   Loop3_022:
  648.    mov eax,edi;
  649.    add eax,3;
  650.    sub eax,ecx;
  651.    mov es:#edx,#eax;
  652.    inc edx;
  653.   loop Loop3_022;
  654.  
  655.   mov #edx,0;
  656.   inc edx;
  657.   mov #edx,0;
  658.   inc edx;
  659.   mov #edx,0;
  660.   inc edx;
  661.   mov #edx,0;
  662.   inc edx;
  663.   mov #edx,0;
  664.  
  665. // mov ecx,floppy;
  666. // add ecx,12;
  667. // mov ecx,#ecx; //Get FAT size - why?
  668. // mov eax,floppy;
  669. // add eax,8205; //FAT - why?
  670. // Loop1_022:
  671. //  cmp #eax,0;
  672. //  je SpaceFound_022;
  673. //  inc eax;
  674. // loop Loop1_022;
  675. // jmp End_022;
  676. //
  677. // SpaceFound_022:
  678. //  mov es:#eax,-1;
  679. //  mov ecx,eax;
  680. //  sub ecx,floppy;
  681. //  sub ecx,8205;
  682. //  out 0,ecx;
  683. //  mul ecx,16;
  684. //  mov eax,floppy;
  685. //  add eax,12;
  686. //  add eax,ecx;
  687. //
  688. //  mov ecx,8;
  689. //  Loop2_022:
  690. //   mov edx,esi;
  691. //   add edx,8;
  692. //   sub edx,ecx;
  693. //   mov #eax,#edx;
  694. //   inc eax;
  695. //  loop Loop2_022;
  696. //  
  697. //  mov ecx,3;
  698. //  Loop3_022:
  699. //   mov edx,edi;
  700. //   add edx,3;
  701. //   sub edx,ecx;
  702. //   mov #eax,#edx;
  703. //   inc eax;
  704. //  loop Loop3_022;
  705. //
  706. //  mov #eax,0;
  707. //  inc eax;
  708. //  mov #eax,0;
  709. //  inc eax;
  710. //  mov #eax,0;
  711. //  inc eax;
  712. //  mov #eax,0;
  713. //  inc eax;
  714. //  mov #eax,0;
  715.  
  716.  End_022:
  717.  pop es;
  718.  pop eax;
  719.  pop ecx;
  720.  pop edx;
  721. ret
  722.  
  723. Filename: db 'asdfghjk';
  724. Filename2: db 'sadfghjk';
  725. Extension: db 'txt';
  726.  
  727. codestart:
  728.  stp;
  729.  sti;
  730.  lidtr InterruptHandler;
  731.  mov edi,InterruptHandler;
  732.  add edi,28;
  733.  mov #edi,MemoryError;
  734.  inc edi;
  735.  mov #edi,0;
  736.  inc edi;
  737.  mov #edi,0;
  738.  inc edi;
  739.  mov #edi,32;
  740.  
  741.     call ClearScreen;
  742.     mov edx,0;
  743.  mov port1,0;
  744.  mov port2,0;
  745.  mov port3,0;
  746.  mov port4,0;
  747.  mov port5,0;
  748.  mov port6,0;
  749.  mov port7,0;
  750.  mov port8,0;
  751.  
  752.  call WriteCommandChar;
  753.  
  754. realstart:
  755.     call ReadKey;
  756.  cmp eax,0;
  757.     cne ProcessKey;
  758.  je realstart;
  759.  
  760.  call WriteInputBuffer;
  761.  
  762. //call FormatDisc;
  763. //
  764. //mov esi,Filename;
  765. //mov edi,Extension;
  766. //call MakeFile;
  767.  
  768. //mov esi,Filename2;
  769. //call MakeFile;
  770.  
  771. jmp realstart;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement