?login_element?

Subversion Repositories NedoOS

Rev

Rev 1928 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <oscalls.h>
  5. #include <intrz80.h>
  6. #include <terminal.c>
  7. #define datareg 179
  8. #define cmdreg 187
  9. #include <booter.c>
  10.  
  11. unsigned char getStat(void)
  12. {
  13.     // Принять данные из регистра статуса
  14.     unsigned char dataread;
  15.     dataread = input(cmdreg);
  16.     return dataread;
  17. }
  18.  
  19. unsigned char getDat(void)
  20. {
  21.     // Принять данные из регистра данных
  22.     unsigned char dataread;
  23.     dataread = input(datareg);
  24.     return dataread;
  25. }
  26.  
  27. void sendDat(unsigned char data)
  28. {
  29.     // Послать код команды в регистр команд
  30.     unsigned char dataread2;
  31.     output(datareg, data);
  32.     dataread2 = 128;
  33.     while (dataread2 != 0)
  34.     {
  35.         dataread2 = (input(cmdreg) & 128);
  36.     }
  37. }
  38.  
  39. void sendDatnv(unsigned char data)
  40. {
  41.     // Послать данные в регистр данных, без ожидания готовности
  42.     output(datareg, data);
  43. }
  44.  
  45. void sendCmd(unsigned char command)
  46. {
  47.     // Послать код команды в регистр команд
  48.     unsigned char dataread2;
  49.     output(cmdreg, command);
  50.     dataread2 = 1;
  51.     while (dataread2 == 1)
  52.     {
  53.         dataread2 = input(cmdreg) & 1;
  54.     }
  55. }
  56.  
  57. void resetGS(void)
  58. {
  59.     sendCmd(0xF4);
  60. }
  61.  
  62. unsigned long getMem(void)
  63. {
  64.     unsigned char ramL, ramM, RamH;
  65.     sendCmd(0x20);
  66.     ramL = getDat();
  67.     ramM = getDat();
  68.     RamH = getDat();
  69.     return (65536 * RamH + 256 * ramM + ramL);
  70. }
  71.  
  72. /* Convert an int to it's binary representation */
  73. char *int2bin(int num, int pad)
  74. {
  75.  char *str = malloc(sizeof(char) * (pad+1));
  76.   if (str) {
  77.    str[pad]='\0';
  78.    while (--pad>=0) {
  79.     str[pad] = num & 1 ? '1' : '0';
  80.     num >>= 1;
  81.    }
  82.   } else {
  83.    return "";
  84.   }
  85.  return str;
  86. }
  87.  
  88. C_task main(void)
  89. {
  90.     unsigned char dataread, modHandle, q, qdec;
  91.     unsigned long loadloop;
  92.     os_initstdio();
  93.  
  94.     getDat();
  95.  
  96.     BOX(1, 1, 80, 25, 40);
  97.     AT(23, 1);
  98.     ATRIB(92);
  99.     printf("[GENERAL SOUND LOW LEVEL TESTER]\r\n\r\n");
  100.  
  101.     printf("Testing  STATUS register 0xBB \r\n\r\n");
  102.  
  103.     qdec = getStat();
  104.     q = qdec & 129; // 10000001
  105.  
  106.     switch (q)
  107.     {
  108.     case 0:
  109.         printf("  DATA bit and COMMAND bit are reset [0xxxxxx0][%u][%s]. OK.\r\n\r\n",qdec , int2bin(qdec, 8));
  110.         break;
  111.     case 129:
  112.         printf("  DATA bit and COMMAND bit are set [1xxxxxx1][%u][%s]. FAIL.\r\n\r\n",qdec , int2bin(qdec, 8));
  113.         break;
  114.     case 128:
  115.         printf("  DATA bit are set [1xxxxxx0][%u][%s]. FAIL. \r\n\r\n",qdec , int2bin(qdec, 8));
  116.         break;
  117.     case 1:
  118.         printf("  COMMAND bit are set [0xxxxxx1][%u][%s]. FAIL. \r\n\r\n",qdec , int2bin(qdec, 8));
  119.     default:
  120.         printf("  Error detecting status. [%u][%s]. FAIL.\r\n\r\n",qdec , int2bin(qdec, 8));
  121.     }
  122.  
  123.     printf("Resetting GS... \r\n");
  124.     resetGS();
  125.     printf("Reset OK. Internal memory test...\r\n\r\n");
  126.  
  127.     dataread = 0;
  128.     while (dataread == 0)
  129.     {
  130.         dataread = input(datareg);
  131.     }
  132.  
  133.     printf("Reported by boot : %u pages\r\n", dataread);
  134.     printf("Reported by 0x20 : %lu bytes\r\n\r\n", getMem());
  135.  
  136.     sendCmd(0xFA);
  137.     printf("sendCmd (0xFA) - Test mode on;\r\n");
  138.     sendCmd(11);
  139.     printf("sendCmd (11)   - Sound in chanel #1;\r\n");
  140.     sendCmd(12);
  141.     printf("sendCmd (12)   - Sound in chanel #2;\r\n");
  142.     sendCmd(13);
  143.     printf("sendCmd (13)   - Sound in chanel #3;\r\n");
  144.     sendCmd(14);
  145.     printf("sendCmd (14)   - Sound in chanel #4;\r\n\r\n");
  146.  
  147.     printf("Uploading test tune...\r\n");
  148.     sendCmd(0x30);
  149.     modHandle = getDat();
  150.     sendCmd(0xD1);
  151.     for (loadloop = 0; loadloop < sizeof(rawData); loadloop++)
  152.     {
  153.         sendDat(rawData[loadloop]);
  154.     }
  155.     sendCmd(0xD2);
  156.     loadloop = sizeof(rawData);
  157.     printf("%lu bytes uploaded.\r\n", loadloop);
  158.     sendDatnv(modHandle);
  159.     sendCmd(0x31);
  160.     printf("Playing handle %u...\r\n", modHandle);
  161.  
  162.     do
  163.     {
  164.     } while (_low_level_get() == 0);
  165.     sendCmd(0xf3);
  166.     return 0;
  167. }
  168.