Advertisement
cfrantz

Time MMC5 for multiplies

Jul 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4.  
  5. #include "neslib.h"
  6.  
  7. #define NTADR(x,y)  ((0x2000|((y)<<5)|x))
  8.  
  9. #define MSB(x)      (((x)>>8))
  10. #define LSB(x)      (((x)&0xff))
  11.  
  12. #define writereg8(reg_, val_) ( *(uint8_t*)(reg_) = val_ )
  13. #define readreg8(reg_) ( *(uint8_t*)(reg_) )
  14.  
  15. #define writereg16(reg_, val_) ( *(uint16_t*)(reg_) = val_ )
  16. #define readreg16(reg_) ( *(uint16_t*)(reg_) )
  17.  
  18. //////////////////////////////////////////////////////////////////////
  19. // I hacked fceux to put whatever is written to memory location
  20. // 0x4040 to stdout.  Hooray, now I can have printf style debugging
  21. // in my program.
  22. //////////////////////////////////////////////////////////////////////
  23. #define xputc(ch) ( *(char*)0x4040 = ch )
  24. #define measure() ( *(char*)0x4041 )
  25. void write(int fd, const char *buf, int len)
  26. {
  27.     while(len--) {
  28.         xputc(*buf++);
  29.     }
  30. }
  31.  
  32. #if 0
  33. uint16_t mult(uint8_t a, uint8_t b) {
  34.     writereg8(0x5205, a);
  35.     writereg8(0x5206, b);
  36.     return readreg16(0x5205);
  37. }
  38. #else
  39. #define mult(a, b) ( \
  40.     writereg8(0x5205, a), \
  41.     writereg8(0x5206, b), \
  42.     readreg16(0x5205) )
  43. #endif
  44.  
  45. void main(void)
  46. {
  47.     uint8_t a, b;
  48.     uint16_t c;
  49.     char k;
  50.  
  51.     k = measure();
  52.     a = 0;
  53.     do {
  54.         b = 0;
  55.         do {
  56.             c = mult(a, b);
  57.             b = b + 1;
  58.         } while(b);
  59.         a = a + 1;
  60.     } while(a);
  61.     k = measure();
  62.  
  63.     for(;;) {}
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement